[llvm-branch-commits] [cfe-branch] r156378 [1/2] - in /cfe/branches/tooling: ./ bindings/python/clang/ bindings/python/tests/cindex/ docs/ examples/ include/clang-c/ include/clang/AST/ include/clang/Analysis/ include/clang/Analysis/Analyses/ include/clang/Basic/ include/clang/Driver/ include/clang/Frontend/ include/clang/Lex/ include/clang/Parse/ include/clang/Rewrite/ include/clang/Sema/ include/clang/Serialization/ include/clang/StaticAnalyzer/Core/PathSensitive/ include/clang/Tooling/ lib/ARCMigrate/ lib/AST/ lib/Analysis/...
Manuel Klimek
klimek at google.com
Tue May 8 01:47:33 PDT 2012
Author: klimek
Date: Tue May 8 03:47:31 2012
New Revision: 156378
URL: http://llvm.org/viewvc/llvm-project?rev=156378&view=rev
Log:
Integrating mainline.
Added:
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h
- copied unchanged from r156373, cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h
cfe/branches/tooling/lib/StaticAnalyzer/Core/APSIntType.cpp
- copied unchanged from r156373, cfe/trunk/lib/StaticAnalyzer/Core/APSIntType.cpp
cfe/branches/tooling/test/Analysis/additive-folding.cpp
- copied unchanged from r156373, cfe/trunk/test/Analysis/additive-folding.cpp
cfe/branches/tooling/test/Analysis/svalbuilder-logic.c
- copied unchanged from r156373, cfe/trunk/test/Analysis/svalbuilder-logic.c
cfe/branches/tooling/test/CXX/basic/basic.lookup/basic.lookup.classref/p1-cxx11.cpp
- copied unchanged from r156373, cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.classref/p1-cxx11.cpp
cfe/branches/tooling/test/CXX/basic/basic.lookup/basic.lookup.classref/p4-cxx11.cpp
- copied unchanged from r156373, cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.classref/p4-cxx11.cpp
cfe/branches/tooling/test/CXX/special/class.copy/p23-cxx11.cpp
- copied unchanged from r156373, cfe/trunk/test/CXX/special/class.copy/p23-cxx11.cpp
cfe/branches/tooling/test/CodeGen/debug-info-gline-tables-only.c
- copied unchanged from r156373, cfe/trunk/test/CodeGen/debug-info-gline-tables-only.c
cfe/branches/tooling/test/CodeGen/debug-info-gline-tables-only2.c
- copied unchanged from r156373, cfe/trunk/test/CodeGen/debug-info-gline-tables-only2.c
cfe/branches/tooling/test/CodeGenCXX/debug-info-determinism.cpp
- copied unchanged from r156373, cfe/trunk/test/CodeGenCXX/debug-info-determinism.cpp
cfe/branches/tooling/test/CodeGenCXX/debug-info-gline-tables-only.cpp
- copied unchanged from r156373, cfe/trunk/test/CodeGenCXX/debug-info-gline-tables-only.cpp
cfe/branches/tooling/test/CodeGenCXX/member-data-pointers.cpp
- copied unchanged from r156373, cfe/trunk/test/CodeGenCXX/member-data-pointers.cpp
cfe/branches/tooling/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
- copied unchanged from r156373, cfe/trunk/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
cfe/branches/tooling/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
- copied unchanged from r156373, cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
cfe/branches/tooling/test/CodeGenObjC/getter-property-mismatch.m
- copied unchanged from r156373, cfe/trunk/test/CodeGenObjC/getter-property-mismatch.m
cfe/branches/tooling/test/Driver/fpack-struct.c
- copied unchanged from r156373, cfe/trunk/test/Driver/fpack-struct.c
cfe/branches/tooling/test/Driver/warning-options.cpp
- copied unchanged from r156373, cfe/trunk/test/Driver/warning-options.cpp
cfe/branches/tooling/test/Index/availability.c
- copied unchanged from r156373, cfe/trunk/test/Index/availability.c
cfe/branches/tooling/test/Index/index-many-call-ops.cpp
- copied unchanged from r156373, cfe/trunk/test/Index/index-many-call-ops.cpp
cfe/branches/tooling/test/Lexer/wchar-signedness.c
- copied unchanged from r156373, cfe/trunk/test/Lexer/wchar-signedness.c
cfe/branches/tooling/test/Misc/diag-trailing-null-bytes.cpp
- copied unchanged from r156373, cfe/trunk/test/Misc/diag-trailing-null-bytes.cpp
cfe/branches/tooling/test/PCH/remap-file-from-pch.cpp
- copied unchanged from r156373, cfe/trunk/test/PCH/remap-file-from-pch.cpp
cfe/branches/tooling/test/PCH/remap-file-from-pch.cpp.h
- copied unchanged from r156373, cfe/trunk/test/PCH/remap-file-from-pch.cpp.h
cfe/branches/tooling/test/PCH/remap-file-from-pch.cpp.remap.h
- copied unchanged from r156373, cfe/trunk/test/PCH/remap-file-from-pch.cpp.remap.h
cfe/branches/tooling/test/Parser/recursion-limits.cpp
- copied unchanged from r156373, cfe/trunk/test/Parser/recursion-limits.cpp
cfe/branches/tooling/test/Rewriter/rewrite-modern-default-property-synthesis.mm
- copied unchanged from r156373, cfe/trunk/test/Rewriter/rewrite-modern-default-property-synthesis.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-ivar-access.mm
- copied unchanged from r156373, cfe/trunk/test/Rewriter/rewrite-modern-ivar-access.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-private-ivars.mm
- copied unchanged from r156373, cfe/trunk/test/Rewriter/rewrite-modern-private-ivars.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-struct-ivar-1.mm
- copied unchanged from r156373, cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar-1.mm
cfe/branches/tooling/test/Sema/Inputs/format-unused-system-args.h
- copied unchanged from r156373, cfe/trunk/test/Sema/Inputs/format-unused-system-args.h
cfe/branches/tooling/test/SemaCXX/attr-visibility.cpp
- copied unchanged from r156373, cfe/trunk/test/SemaCXX/attr-visibility.cpp
cfe/branches/tooling/test/SemaCXX/offsetof-0x.cpp
- copied unchanged from r156373, cfe/trunk/test/SemaCXX/offsetof-0x.cpp
cfe/branches/tooling/test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp
- copied unchanged from r156373, cfe/trunk/test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp
cfe/branches/tooling/test/SemaCXX/switch-implicit-fallthrough.cpp
- copied unchanged from r156373, cfe/trunk/test/SemaCXX/switch-implicit-fallthrough.cpp
cfe/branches/tooling/test/SemaCXX/warn-loop-analysis.cpp
- copied unchanged from r156373, cfe/trunk/test/SemaCXX/warn-loop-analysis.cpp
cfe/branches/tooling/test/SemaObjC/format-strings-system.h
- copied unchanged from r156373, cfe/trunk/test/SemaObjC/format-strings-system.h
cfe/branches/tooling/test/SemaObjCXX/crash.mm
- copied unchanged from r156373, cfe/trunk/test/SemaObjCXX/crash.mm
cfe/branches/tooling/test/Tooling/clang-check-chdir.cpp
- copied unchanged from r156373, cfe/trunk/test/Tooling/clang-check-chdir.cpp
cfe/branches/tooling/tools/libclang/RecursiveASTVisitor.h
- copied unchanged from r156373, cfe/trunk/tools/libclang/RecursiveASTVisitor.h
Removed:
cfe/branches/tooling/lib/Driver/CC1Options.cpp
cfe/branches/tooling/lib/Headers/intrin.h
cfe/branches/tooling/test/Analysis/additive-folding.c
cfe/branches/tooling/test/CodeGenCXX/member-pointer-type-convert.cpp
cfe/branches/tooling/test/CodeGenCXX/virt-call-offsets.cpp
cfe/branches/tooling/test/CodeGenCXX/x86-64-abi-sret-vs-2word-struct-param.cpp
cfe/branches/tooling/test/Headers/ms-intrin.c
cfe/branches/tooling/test/Misc/wnull-character.cpp
Modified:
cfe/branches/tooling/ (props changed)
cfe/branches/tooling/bindings/python/clang/cindex.py
cfe/branches/tooling/bindings/python/tests/cindex/test_cursor.py
cfe/branches/tooling/bindings/python/tests/cindex/test_translation_unit.py
cfe/branches/tooling/bindings/python/tests/cindex/test_type.py
cfe/branches/tooling/bindings/python/tests/cindex/util.py
cfe/branches/tooling/docs/LanguageExtensions.html
cfe/branches/tooling/docs/ReleaseNotes.html
cfe/branches/tooling/docs/UsersManual.html
cfe/branches/tooling/examples/CMakeLists.txt
cfe/branches/tooling/include/clang-c/Index.h
cfe/branches/tooling/include/clang/AST/ASTContext.h
cfe/branches/tooling/include/clang/AST/Attr.h
cfe/branches/tooling/include/clang/AST/Decl.h
cfe/branches/tooling/include/clang/AST/DeclBase.h
cfe/branches/tooling/include/clang/AST/DeclCXX.h
cfe/branches/tooling/include/clang/AST/DeclTemplate.h
cfe/branches/tooling/include/clang/AST/DeclarationName.h
cfe/branches/tooling/include/clang/AST/ExprCXX.h
cfe/branches/tooling/include/clang/AST/RecordLayout.h
cfe/branches/tooling/include/clang/AST/RecursiveASTVisitor.h
cfe/branches/tooling/include/clang/AST/Type.h
cfe/branches/tooling/include/clang/Analysis/Analyses/FormatString.h
cfe/branches/tooling/include/clang/Analysis/AnalysisContext.h
cfe/branches/tooling/include/clang/Analysis/CFG.h
cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h
cfe/branches/tooling/include/clang/Basic/Attr.td
cfe/branches/tooling/include/clang/Basic/Builtins.def
cfe/branches/tooling/include/clang/Basic/BuiltinsX86.def
cfe/branches/tooling/include/clang/Basic/Diagnostic.h
cfe/branches/tooling/include/clang/Basic/DiagnosticCommonKinds.td
cfe/branches/tooling/include/clang/Basic/DiagnosticGroups.td
cfe/branches/tooling/include/clang/Basic/DiagnosticLexKinds.td
cfe/branches/tooling/include/clang/Basic/DiagnosticParseKinds.td
cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td
cfe/branches/tooling/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/branches/tooling/include/clang/Basic/FileManager.h
cfe/branches/tooling/include/clang/Basic/IdentifierTable.h
cfe/branches/tooling/include/clang/Basic/PartialDiagnostic.h
cfe/branches/tooling/include/clang/Basic/SourceManager.h
cfe/branches/tooling/include/clang/Basic/TokenKinds.def
cfe/branches/tooling/include/clang/Driver/CC1Options.h
cfe/branches/tooling/include/clang/Driver/CC1Options.td
cfe/branches/tooling/include/clang/Driver/CMakeLists.txt
cfe/branches/tooling/include/clang/Driver/Makefile
cfe/branches/tooling/include/clang/Driver/OptParser.td
cfe/branches/tooling/include/clang/Driver/OptTable.h
cfe/branches/tooling/include/clang/Driver/Option.h
cfe/branches/tooling/include/clang/Driver/Options.td
cfe/branches/tooling/include/clang/Driver/ToolChain.h
cfe/branches/tooling/include/clang/Frontend/CodeGenOptions.h
cfe/branches/tooling/include/clang/Lex/Lexer.h
cfe/branches/tooling/include/clang/Lex/LiteralSupport.h
cfe/branches/tooling/include/clang/Parse/Parser.h
cfe/branches/tooling/include/clang/Rewrite/TokenRewriter.h
cfe/branches/tooling/include/clang/Sema/AttributeList.h
cfe/branches/tooling/include/clang/Sema/DeclSpec.h
cfe/branches/tooling/include/clang/Sema/DelayedDiagnostic.h
cfe/branches/tooling/include/clang/Sema/Overload.h
cfe/branches/tooling/include/clang/Sema/Sema.h
cfe/branches/tooling/include/clang/Sema/TemplateDeduction.h
cfe/branches/tooling/include/clang/Serialization/ASTReader.h
cfe/branches/tooling/include/clang/Serialization/ASTWriter.h
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/ObjCMessage.h
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
cfe/branches/tooling/include/clang/Tooling/Tooling.h
cfe/branches/tooling/lib/ARCMigrate/FileRemapper.cpp
cfe/branches/tooling/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp
cfe/branches/tooling/lib/ARCMigrate/TransGCAttrs.cpp
cfe/branches/tooling/lib/ARCMigrate/TransProperties.cpp
cfe/branches/tooling/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp
cfe/branches/tooling/lib/ARCMigrate/Transforms.cpp
cfe/branches/tooling/lib/AST/APValue.cpp
cfe/branches/tooling/lib/AST/ASTContext.cpp
cfe/branches/tooling/lib/AST/ASTImporter.cpp
cfe/branches/tooling/lib/AST/Decl.cpp
cfe/branches/tooling/lib/AST/DeclBase.cpp
cfe/branches/tooling/lib/AST/DeclCXX.cpp
cfe/branches/tooling/lib/AST/DeclObjC.cpp
cfe/branches/tooling/lib/AST/DeclPrinter.cpp
cfe/branches/tooling/lib/AST/DeclTemplate.cpp
cfe/branches/tooling/lib/AST/DeclarationName.cpp
cfe/branches/tooling/lib/AST/Expr.cpp
cfe/branches/tooling/lib/AST/ExprCXX.cpp
cfe/branches/tooling/lib/AST/ExprConstant.cpp
cfe/branches/tooling/lib/AST/ItaniumMangle.cpp
cfe/branches/tooling/lib/AST/MicrosoftMangle.cpp
cfe/branches/tooling/lib/AST/RecordLayout.cpp
cfe/branches/tooling/lib/AST/RecordLayoutBuilder.cpp
cfe/branches/tooling/lib/AST/Type.cpp
cfe/branches/tooling/lib/AST/TypePrinter.cpp
cfe/branches/tooling/lib/AST/VTableBuilder.cpp
cfe/branches/tooling/lib/Analysis/AnalysisDeclContext.cpp
cfe/branches/tooling/lib/Analysis/CFG.cpp
cfe/branches/tooling/lib/Analysis/FormatString.cpp
cfe/branches/tooling/lib/Analysis/UninitializedValues.cpp
cfe/branches/tooling/lib/Basic/FileManager.cpp
cfe/branches/tooling/lib/Basic/IdentifierTable.cpp
cfe/branches/tooling/lib/Basic/SourceManager.cpp
cfe/branches/tooling/lib/Basic/Targets.cpp
cfe/branches/tooling/lib/CodeGen/BackendUtil.cpp
cfe/branches/tooling/lib/CodeGen/CGBlocks.cpp
cfe/branches/tooling/lib/CodeGen/CGBuiltin.cpp
cfe/branches/tooling/lib/CodeGen/CGCXX.cpp
cfe/branches/tooling/lib/CodeGen/CGCXXABI.cpp
cfe/branches/tooling/lib/CodeGen/CGCXXABI.h
cfe/branches/tooling/lib/CodeGen/CGCall.cpp
cfe/branches/tooling/lib/CodeGen/CGClass.cpp
cfe/branches/tooling/lib/CodeGen/CGDebugInfo.cpp
cfe/branches/tooling/lib/CodeGen/CGDecl.cpp
cfe/branches/tooling/lib/CodeGen/CGDeclCXX.cpp
cfe/branches/tooling/lib/CodeGen/CGExpr.cpp
cfe/branches/tooling/lib/CodeGen/CGExprAgg.cpp
cfe/branches/tooling/lib/CodeGen/CGExprCXX.cpp
cfe/branches/tooling/lib/CodeGen/CGExprConstant.cpp
cfe/branches/tooling/lib/CodeGen/CGExprScalar.cpp
cfe/branches/tooling/lib/CodeGen/CGObjC.cpp
cfe/branches/tooling/lib/CodeGen/CGObjCGNU.cpp
cfe/branches/tooling/lib/CodeGen/CGObjCMac.cpp
cfe/branches/tooling/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/branches/tooling/lib/CodeGen/CGStmt.cpp
cfe/branches/tooling/lib/CodeGen/CodeGenFunction.cpp
cfe/branches/tooling/lib/CodeGen/CodeGenFunction.h
cfe/branches/tooling/lib/CodeGen/CodeGenModule.cpp
cfe/branches/tooling/lib/CodeGen/CodeGenModule.h
cfe/branches/tooling/lib/CodeGen/ItaniumCXXABI.cpp
cfe/branches/tooling/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/branches/tooling/lib/CodeGen/TargetInfo.cpp
cfe/branches/tooling/lib/Driver/CMakeLists.txt
cfe/branches/tooling/lib/Driver/Compilation.cpp
cfe/branches/tooling/lib/Driver/Driver.cpp
cfe/branches/tooling/lib/Driver/OptTable.cpp
cfe/branches/tooling/lib/Driver/ToolChains.cpp
cfe/branches/tooling/lib/Driver/ToolChains.h
cfe/branches/tooling/lib/Driver/Tools.cpp
cfe/branches/tooling/lib/Frontend/CMakeLists.txt
cfe/branches/tooling/lib/Frontend/CompilerInstance.cpp
cfe/branches/tooling/lib/Frontend/CompilerInvocation.cpp
cfe/branches/tooling/lib/Frontend/InitPreprocessor.cpp
cfe/branches/tooling/lib/Frontend/LayoutOverrideSource.cpp
cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp
cfe/branches/tooling/lib/FrontendTool/CMakeLists.txt
cfe/branches/tooling/lib/FrontendTool/ExecuteCompilerInvocation.cpp
cfe/branches/tooling/lib/Headers/CMakeLists.txt
cfe/branches/tooling/lib/Headers/emmintrin.h
cfe/branches/tooling/lib/Lex/LiteralSupport.cpp
cfe/branches/tooling/lib/Parse/ParseCXXInlineMethods.cpp
cfe/branches/tooling/lib/Parse/ParseDecl.cpp
cfe/branches/tooling/lib/Parse/ParseDeclCXX.cpp
cfe/branches/tooling/lib/Parse/ParseExpr.cpp
cfe/branches/tooling/lib/Parse/ParseExprCXX.cpp
cfe/branches/tooling/lib/Parse/ParseObjc.cpp
cfe/branches/tooling/lib/Parse/ParseStmt.cpp
cfe/branches/tooling/lib/Parse/ParseTemplate.cpp
cfe/branches/tooling/lib/Parse/ParseTentative.cpp
cfe/branches/tooling/lib/Parse/Parser.cpp
cfe/branches/tooling/lib/Parse/RAIIObjectsForParser.h
cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp
cfe/branches/tooling/lib/Rewrite/RewriteObjC.cpp
cfe/branches/tooling/lib/Sema/AnalysisBasedWarnings.cpp
cfe/branches/tooling/lib/Sema/AttributeList.cpp
cfe/branches/tooling/lib/Sema/DeclSpec.cpp
cfe/branches/tooling/lib/Sema/IdentifierResolver.cpp
cfe/branches/tooling/lib/Sema/Sema.cpp
cfe/branches/tooling/lib/Sema/SemaAccess.cpp
cfe/branches/tooling/lib/Sema/SemaCXXScopeSpec.cpp
cfe/branches/tooling/lib/Sema/SemaCast.cpp
cfe/branches/tooling/lib/Sema/SemaChecking.cpp
cfe/branches/tooling/lib/Sema/SemaCodeComplete.cpp
cfe/branches/tooling/lib/Sema/SemaDecl.cpp
cfe/branches/tooling/lib/Sema/SemaDeclAttr.cpp
cfe/branches/tooling/lib/Sema/SemaDeclCXX.cpp
cfe/branches/tooling/lib/Sema/SemaDeclObjC.cpp
cfe/branches/tooling/lib/Sema/SemaExceptionSpec.cpp
cfe/branches/tooling/lib/Sema/SemaExpr.cpp
cfe/branches/tooling/lib/Sema/SemaExprCXX.cpp
cfe/branches/tooling/lib/Sema/SemaExprMember.cpp
cfe/branches/tooling/lib/Sema/SemaExprObjC.cpp
cfe/branches/tooling/lib/Sema/SemaFixItUtils.cpp
cfe/branches/tooling/lib/Sema/SemaInit.cpp
cfe/branches/tooling/lib/Sema/SemaLambda.cpp
cfe/branches/tooling/lib/Sema/SemaLookup.cpp
cfe/branches/tooling/lib/Sema/SemaObjCProperty.cpp
cfe/branches/tooling/lib/Sema/SemaOverload.cpp
cfe/branches/tooling/lib/Sema/SemaPseudoObject.cpp
cfe/branches/tooling/lib/Sema/SemaStmt.cpp
cfe/branches/tooling/lib/Sema/SemaStmtAttr.cpp
cfe/branches/tooling/lib/Sema/SemaTemplate.cpp
cfe/branches/tooling/lib/Sema/SemaTemplateDeduction.cpp
cfe/branches/tooling/lib/Sema/SemaTemplateInstantiate.cpp
cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/branches/tooling/lib/Sema/SemaType.cpp
cfe/branches/tooling/lib/Sema/TargetAttributesSema.cpp
cfe/branches/tooling/lib/Serialization/ASTReader.cpp
cfe/branches/tooling/lib/Serialization/ASTReaderDecl.cpp
cfe/branches/tooling/lib/Serialization/ASTReaderStmt.cpp
cfe/branches/tooling/lib/Serialization/ASTWriter.cpp
cfe/branches/tooling/lib/Serialization/ASTWriterDecl.cpp
cfe/branches/tooling/lib/Serialization/ASTWriterStmt.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/Checkers.td
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/BasicConstraintManager.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/CMakeLists.txt
cfe/branches/tooling/lib/StaticAnalyzer/Core/Environment.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineC.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/ObjCMessage.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/SValBuilder.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.h
cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Core/SymbolManager.cpp
cfe/branches/tooling/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
cfe/branches/tooling/lib/Tooling/Tooling.cpp
cfe/branches/tooling/test/Analysis/additive-folding-range-constraints.c
cfe/branches/tooling/test/Analysis/bstring.c
cfe/branches/tooling/test/Analysis/constant-folding.c
cfe/branches/tooling/test/Analysis/inline-plist.c
cfe/branches/tooling/test/Analysis/malloc-plist.c
cfe/branches/tooling/test/Analysis/malloc-sizeof.c
cfe/branches/tooling/test/Analysis/malloc.c
cfe/branches/tooling/test/Analysis/malloc.cpp
cfe/branches/tooling/test/Analysis/malloc.m
cfe/branches/tooling/test/Analysis/malloc.mm
cfe/branches/tooling/test/Analysis/misc-ps-region-store.cpp
cfe/branches/tooling/test/Analysis/misc-ps-region-store.m
cfe/branches/tooling/test/Analysis/misc-ps.m
cfe/branches/tooling/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
cfe/branches/tooling/test/Analysis/out-of-bounds.c
cfe/branches/tooling/test/Analysis/retain-release.m
cfe/branches/tooling/test/Analysis/stack-addr-ps.cpp
cfe/branches/tooling/test/Analysis/string.c
cfe/branches/tooling/test/Analysis/system-header-simulator-objc.h
cfe/branches/tooling/test/Analysis/system-header-simulator.h
cfe/branches/tooling/test/Analysis/taint-generic.c
cfe/branches/tooling/test/CXX/class/class.mem/p2.cpp
cfe/branches/tooling/test/CXX/expr/expr.post/expr.reinterpret.cast/p1-0x.cpp
cfe/branches/tooling/test/CXX/expr/expr.prim/expr.prim.general/p3-0x.cpp
cfe/branches/tooling/test/CXX/special/class.copy/p11.0x.copy.cpp
cfe/branches/tooling/test/CXX/special/class.ctor/p5-0x.cpp
cfe/branches/tooling/test/CXX/special/class.ctor/p6-0x.cpp
cfe/branches/tooling/test/CXX/special/class.dtor/p5-0x.cpp
cfe/branches/tooling/test/CXX/special/class.inhctor/elsewhere.cpp
cfe/branches/tooling/test/CXX/special/class.inhctor/p3.cpp
cfe/branches/tooling/test/CXX/special/class.inhctor/p7.cpp
cfe/branches/tooling/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
cfe/branches/tooling/test/CXX/temp/temp.spec/temp.explicit/p12.cpp
cfe/branches/tooling/test/CodeGen/annotations-builtin.c
cfe/branches/tooling/test/CodeGen/blocks.c
cfe/branches/tooling/test/CodeGen/builtins-x86.c
cfe/branches/tooling/test/CodeGen/catch-undef-behavior.c
cfe/branches/tooling/test/CodeGen/sse-builtins.c
cfe/branches/tooling/test/CodeGenCXX/class-layout.cpp
cfe/branches/tooling/test/CodeGenCXX/const-init-cxx11.cpp
cfe/branches/tooling/test/CodeGenCXX/destructors.cpp
cfe/branches/tooling/test/CodeGenCXX/inheriting-constructor.cpp
cfe/branches/tooling/test/CodeGenCXX/mangle-ms.cpp
cfe/branches/tooling/test/CodeGenCXX/member-function-pointers.cpp
cfe/branches/tooling/test/CodeGenCXX/member-init-anon-union.cpp
cfe/branches/tooling/test/CodeGenCXX/x86_64-arguments.cpp
cfe/branches/tooling/test/CodeGenObjCXX/encode.mm
cfe/branches/tooling/test/Driver/altivec.cpp
cfe/branches/tooling/test/Driver/debug-options-as.c
cfe/branches/tooling/test/Driver/debug-options.c
cfe/branches/tooling/test/Driver/fast-math.c
cfe/branches/tooling/test/Driver/linux-ld.c
cfe/branches/tooling/test/FixIt/fixit.cpp
cfe/branches/tooling/test/Index/c-index-api-loadTU-test.m
cfe/branches/tooling/test/Index/complete-with-annotations.cpp
cfe/branches/tooling/test/Index/print-typekind.m
cfe/branches/tooling/test/Misc/warning-flags.c
cfe/branches/tooling/test/PCH/objc_methods.h
cfe/branches/tooling/test/Parser/cxx-using-declaration.cpp
cfe/branches/tooling/test/Parser/declarators.c
cfe/branches/tooling/test/Parser/recovery.c
cfe/branches/tooling/test/Preprocessor/init.c
cfe/branches/tooling/test/Rewriter/objc-bool-literal-modern-1.mm
cfe/branches/tooling/test/Rewriter/objc-modern-boxing.mm
cfe/branches/tooling/test/Rewriter/objc-modern-property-attributes.mm
cfe/branches/tooling/test/Rewriter/rewrite-block-literal-1.mm
cfe/branches/tooling/test/Rewriter/rewrite-block-literal.mm
cfe/branches/tooling/test/Rewriter/rewrite-block-pointer.mm
cfe/branches/tooling/test/Rewriter/rewrite-byref-in-nested-blocks.mm
cfe/branches/tooling/test/Rewriter/rewrite-foreach-in-block.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-block-consts.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-block.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-extern-c-func-decl.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-ivars-1.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-struct-ivar.mm
cfe/branches/tooling/test/Rewriter/rewrite-modern-typeof.mm
cfe/branches/tooling/test/Rewriter/rewrite-nested-blocks-1.mm
cfe/branches/tooling/test/Rewriter/rewrite-nested-blocks-2.mm
cfe/branches/tooling/test/Rewriter/rewrite-nested-blocks.mm
cfe/branches/tooling/test/Rewriter/rewrite-nested-property-in-blocks.mm
cfe/branches/tooling/test/Rewriter/rewrite-rewritten-initializer.mm
cfe/branches/tooling/test/Rewriter/rewrite-unique-block-api.mm
cfe/branches/tooling/test/Sema/128bitint.c
cfe/branches/tooling/test/Sema/annotate.c
cfe/branches/tooling/test/Sema/attr-availability.c
cfe/branches/tooling/test/Sema/attr-visibility.c
cfe/branches/tooling/test/Sema/compare.c
cfe/branches/tooling/test/Sema/dllimport-dllexport.c
cfe/branches/tooling/test/Sema/format-strings.c
cfe/branches/tooling/test/Sema/fpack-struct.c
cfe/branches/tooling/test/Sema/ms_class_layout.cpp
cfe/branches/tooling/test/Sema/uninit-variables.c
cfe/branches/tooling/test/Sema/vector-ops.c
cfe/branches/tooling/test/SemaCXX/abstract.cpp
cfe/branches/tooling/test/SemaCXX/constant-expression-cxx11.cpp
cfe/branches/tooling/test/SemaCXX/conversion-function.cpp
cfe/branches/tooling/test/SemaCXX/conversion.cpp
cfe/branches/tooling/test/SemaCXX/cxx98-compat.cpp
cfe/branches/tooling/test/SemaCXX/decl-expr-ambiguity.cpp
cfe/branches/tooling/test/SemaCXX/dependent-noexcept-unevaluated.cpp
cfe/branches/tooling/test/SemaCXX/implicit-exception-spec.cpp
cfe/branches/tooling/test/SemaCXX/invalid-member-expr.cpp
cfe/branches/tooling/test/SemaCXX/type-traits.cpp
cfe/branches/tooling/test/SemaCXX/virtuals.cpp
cfe/branches/tooling/test/SemaCXX/warn-thread-safety-analysis.cpp
cfe/branches/tooling/test/SemaCXX/warn-thread-safety-parsing.cpp
cfe/branches/tooling/test/SemaCXX/warn-unreachable.cpp (props changed)
cfe/branches/tooling/test/SemaObjC/boxing-illegal-types.m
cfe/branches/tooling/test/SemaObjC/default-synthesize-1.m
cfe/branches/tooling/test/SemaObjC/format-strings-objc.m
cfe/branches/tooling/test/SemaObjC/property-10.m
cfe/branches/tooling/test/SemaObjC/property.m
cfe/branches/tooling/test/SemaObjCXX/property-synthesis-error.mm
cfe/branches/tooling/test/SemaTemplate/default-expr-arguments.cpp
cfe/branches/tooling/test/SemaTemplate/instantiate-objc-1.mm
cfe/branches/tooling/test/SemaTemplate/overload-candidates.cpp
cfe/branches/tooling/tools/c-index-test/c-index-test.c
cfe/branches/tooling/tools/driver/cc1_main.cpp
cfe/branches/tooling/tools/driver/driver.cpp
cfe/branches/tooling/tools/libclang/CIndex.cpp
cfe/branches/tooling/tools/libclang/CXCursor.cpp
cfe/branches/tooling/tools/libclang/CXCursor.h
cfe/branches/tooling/tools/libclang/CXTranslationUnit.h
cfe/branches/tooling/tools/libclang/CXType.cpp
cfe/branches/tooling/tools/libclang/IndexBody.cpp
cfe/branches/tooling/tools/libclang/IndexTypeSourceInfo.cpp
cfe/branches/tooling/tools/libclang/libclang.exports
cfe/branches/tooling/unittests/Tooling/RecursiveASTVisitorTest.cpp
cfe/branches/tooling/utils/TableGen/ClangAttrEmitter.cpp
cfe/branches/tooling/utils/TableGen/ClangDiagnosticsEmitter.cpp
Propchange: cfe/branches/tooling/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 8 03:47:31 2012
@@ -1,3 +1,3 @@
/cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:146581-155648
+/cfe/trunk:146581-156373
/cfe/trunk/test/SemaTemplate:126920
Modified: cfe/branches/tooling/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/bindings/python/clang/cindex.py?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/bindings/python/clang/cindex.py (original)
+++ cfe/branches/tooling/bindings/python/clang/cindex.py Tue May 8 03:47:31 2012
@@ -86,6 +86,48 @@
lib = get_cindex_library()
+### Exception Classes ###
+
+class TranslationUnitLoadError(Exception):
+ """Represents an error that occurred when loading a TranslationUnit.
+
+ This is raised in the case where a TranslationUnit could not be
+ instantiated due to failure in the libclang library.
+
+ FIXME: Make libclang expose additional error information in this scenario.
+ """
+ pass
+
+class TranslationUnitSaveError(Exception):
+ """Represents an error that occurred when saving a TranslationUnit.
+
+ Each error has associated with it an enumerated value, accessible under
+ e.save_error. Consumers can compare the value with one of the ERROR_
+ constants in this class.
+ """
+
+ # Indicates that an unknown error occurred. This typically indicates that
+ # I/O failed during save.
+ ERROR_UNKNOWN = 1
+
+ # Indicates that errors during translation prevented saving. The errors
+ # should be available via the TranslationUnit's diagnostics.
+ ERROR_TRANSLATION_ERRORS = 2
+
+ # Indicates that the translation unit was somehow invalid.
+ ERROR_INVALID_TU = 3
+
+ def __init__(self, enumeration, message):
+ assert isinstance(enumeration, int)
+
+ if enumeration < 1 or enumeration > 3:
+ raise Exception("Encountered undefined TranslationUnit save error "
+ "constant: %d. Please file a bug to have this "
+ "value supported." % enumeration)
+
+ self.save_error = enumeration
+ Exception.__init__(self, message)
+
### Structures and Utility Classes ###
class _CXString(Structure):
@@ -1008,6 +1050,30 @@
return self._enum_type
@property
+ def enum_value(self):
+ """Return the value of an enum constant."""
+ if not hasattr(self, '_enum_value'):
+ assert self.kind == CursorKind.ENUM_CONSTANT_DECL
+ # Figure out the underlying type of the enum to know if it
+ # is a signed or unsigned quantity.
+ underlying_type = self.type
+ if underlying_type.kind == TypeKind.ENUM:
+ underlying_type = underlying_type.get_declaration().enum_type
+ if underlying_type.kind in (TypeKind.CHAR_U,
+ TypeKind.UCHAR,
+ TypeKind.CHAR16,
+ TypeKind.CHAR32,
+ TypeKind.USHORT,
+ TypeKind.UINT,
+ TypeKind.ULONG,
+ TypeKind.ULONGLONG,
+ TypeKind.UINT128):
+ self._enum_value = Cursor_enum_const_decl_unsigned(self)
+ else:
+ self._enum_value = Cursor_enum_const_decl(self)
+ return self._enum_value
+
+ @property
def objc_type_encoding(self):
"""Return the Objective-C type encoding as a str."""
if not hasattr(self, '_objc_type_encoding'):
@@ -1023,6 +1089,22 @@
return self._hash
+ @property
+ def semantic_parent(self):
+ """Return the semantic parent for this cursor."""
+ if not hasattr(self, '_semantic_parent'):
+ self._semantic_parent = Cursor_semantic_parent(self)
+
+ return self._semantic_parent
+
+ @property
+ def lexical_parent(self):
+ """Return the lexical parent for this cursor."""
+ if not hasattr(self, '_lexical_parent'):
+ self._lexical_parent = Cursor_lexical_parent(self)
+
+ return self._lexical_parent
+
def get_children(self):
"""Return an iterator for accessing the children of this cursor."""
@@ -1581,15 +1663,11 @@
Index_dispose(self)
def read(self, path):
- """Load the translation unit from the given AST file."""
- ptr = TranslationUnit_read(self, path)
- if ptr:
- return TranslationUnit(ptr)
- return None
+ """Load a TranslationUnit from the given AST file."""
+ return TranslationUnit.from_ast(path, self)
- def parse(self, path, args = [], unsaved_files = [], options = 0):
- """
- Load the translation unit from the given source code file by running
+ def parse(self, path, args=None, unsaved_files=None, options = 0):
+ """Load the translation unit from the given source code file by running
clang and generating the AST before loading. Additional command line
parameters can be passed to clang via the args parameter.
@@ -1597,39 +1675,150 @@
to as unsaved_files, the first item should be the filenames to be mapped
and the second should be the contents to be substituted for the
file. The contents may be passed as strings or file objects.
- """
- arg_array = 0
- if len(args):
- arg_array = (c_char_p * len(args))(* args)
- unsaved_files_array = 0
- if len(unsaved_files):
- unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
- for i,(name,value) in enumerate(unsaved_files):
- if not isinstance(value, str):
- # FIXME: It would be great to support an efficient version
- # of this, one day.
- value = value.read()
- print value
- if not isinstance(value, str):
- raise TypeError,'Unexpected unsaved file contents.'
- unsaved_files_array[i].name = name
- unsaved_files_array[i].contents = value
- unsaved_files_array[i].length = len(value)
- ptr = TranslationUnit_parse(self, path, arg_array, len(args),
- unsaved_files_array, len(unsaved_files),
- options)
- if ptr:
- return TranslationUnit(ptr)
- return None
+ If an error was encountered during parsing, a TranslationUnitLoadError
+ will be raised.
+ """
+ return TranslationUnit.from_source(path, args, unsaved_files, options,
+ self)
class TranslationUnit(ClangObject):
- """
- The TranslationUnit class represents a source code translation unit and
- provides read-only access to its top-level declarations.
+ """Represents a source code translation unit.
+
+ This is one of the main types in the API. Any time you wish to interact
+ with Clang's representation of a source file, you typically start with a
+ translation unit.
"""
- def __init__(self, ptr):
+ # Default parsing mode.
+ PARSE_NONE = 0
+
+ # Instruct the parser to create a detailed processing record containing
+ # metadata not normally retained.
+ PARSE_DETAILED_PROCESSING_RECORD = 1
+
+ # Indicates that the translation unit is incomplete. This is typically used
+ # when parsing headers.
+ PARSE_INCOMPLETE = 2
+
+ # Instruct the parser to create a pre-compiled preamble for the translation
+ # unit. This caches the preamble (included files at top of source file).
+ # This is useful if the translation unit will be reparsed and you don't
+ # want to incur the overhead of reparsing the preamble.
+ PARSE_PRECOMPILED_PREAMBLE = 4
+
+ # Cache code completion information on parse. This adds time to parsing but
+ # speeds up code completion.
+ PARSE_CACHE_COMPLETION_RESULTS = 8
+
+ # Flags with values 16 and 32 are deprecated and intentionally omitted.
+
+ # Do not parse function bodies. This is useful if you only care about
+ # searching for declarations/definitions.
+ PARSE_SKIP_FUNCTION_BODIES = 64
+
+ @classmethod
+ def from_source(cls, filename, args=None, unsaved_files=None, options=0,
+ index=None):
+ """Create a TranslationUnit by parsing source.
+
+ This is capable of processing source code both from files on the
+ filesystem as well as in-memory contents.
+
+ Command-line arguments that would be passed to clang are specified as
+ a list via args. These can be used to specify include paths, warnings,
+ etc. e.g. ["-Wall", "-I/path/to/include"].
+
+ In-memory file content can be provided via unsaved_files. This is an
+ iterable of 2-tuples. The first element is the str filename. The
+ second element defines the content. Content can be provided as str
+ source code or as file objects (anything with a read() method). If
+ a file object is being used, content will be read until EOF and the
+ read cursor will not be reset to its original position.
+
+ options is a bitwise or of TranslationUnit.PARSE_XXX flags which will
+ control parsing behavior.
+
+ To parse source from the filesystem, the filename of the file to parse
+ is specified by the filename argument. Or, filename could be None and
+ the args list would contain the filename(s) to parse.
+
+ To parse source from an in-memory buffer, set filename to the virtual
+ filename you wish to associate with this source (e.g. "test.c"). The
+ contents of that file are then provided in unsaved_files.
+
+ If an error occurs, a TranslationUnitLoadError is raised.
+
+ Please note that a TranslationUnit with parser errors may be returned.
+ It is the caller's responsibility to check tu.diagnostics for errors.
+
+ Also note that Clang infers the source language from the extension of
+ the input filename. If you pass in source code containing a C++ class
+ declaration with the filename "test.c" parsing will fail.
+ """
+ if args is None:
+ args = []
+
+ if unsaved_files is None:
+ unsaved_files = []
+
+ if index is None:
+ index = Index.create()
+
+ args_array = None
+ if len(args) > 0:
+ args_array = (c_char_p * len(args))(* args)
+
+ unsaved_array = None
+ if len(unsaved_files) > 0:
+ unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
+ for i, (name, contents) in enumerate(unsaved_files):
+ if hasattr(contents, "read"):
+ contents = contents.read()
+
+ unsaved_array[i].name = name
+ unsaved_array[i].contents = contents
+ unsaved_array[i].length = len(contents)
+
+ ptr = TranslationUnit_parse(index, filename, args_array, len(args),
+ unsaved_array, len(unsaved_files),
+ options)
+
+ if ptr is None:
+ raise TranslationUnitLoadError("Error parsing translation unit.")
+
+ return cls(ptr, index=index)
+
+ @classmethod
+ def from_ast_file(cls, filename, index=None):
+ """Create a TranslationUnit instance from a saved AST file.
+
+ A previously-saved AST file (provided with -emit-ast or
+ TranslationUnit.save()) is loaded from the filename specified.
+
+ If the file cannot be loaded, a TranslationUnitLoadError will be
+ raised.
+
+ index is optional and is the Index instance to use. If not provided,
+ a default Index will be created.
+ """
+ if index is None:
+ index = Index.create()
+
+ ptr = TranslationUnit_read(index, filename)
+ if ptr is None:
+ raise TranslationUnitLoadError(filename)
+
+ return cls(ptr=ptr, index=index)
+
+ def __init__(self, ptr, index):
+ """Create a TranslationUnit instance.
+
+ TranslationUnits should be created using one of the from_* @classmethod
+ functions above. __init__ is only called internally.
+ """
+ assert isinstance(index, Index)
+
ClangObject.__init__(self, ptr)
def __del__(self):
@@ -1685,7 +1874,7 @@
return DiagIterator(self)
- def reparse(self, unsaved_files = [], options = 0):
+ def reparse(self, unsaved_files=None, options=0):
"""
Reparse an already parsed translation unit.
@@ -1694,6 +1883,9 @@
and the second should be the contents to be substituted for the
file. The contents may be passed as strings or file objects.
"""
+ if unsaved_files is None:
+ unsaved_files = []
+
unsaved_files_array = 0
if len(unsaved_files):
unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
@@ -1711,7 +1903,29 @@
ptr = TranslationUnit_reparse(self, len(unsaved_files),
unsaved_files_array,
options)
- def codeComplete(self, path, line, column, unsaved_files = [], options = 0):
+
+ def save(self, filename):
+ """Saves the TranslationUnit to a file.
+
+ This is equivalent to passing -emit-ast to the clang frontend. The
+ saved file can be loaded back into a TranslationUnit. Or, if it
+ corresponds to a header, it can be used as a pre-compiled header file.
+
+ If an error occurs while saving, a TranslationUnitSaveError is raised.
+ If the error was TranslationUnitSaveError.ERROR_INVALID_TU, this means
+ the constructed TranslationUnit was not valid at time of save. In this
+ case, the reason(s) why should be available via
+ TranslationUnit.diagnostics().
+
+ filename -- The path to save the translation unit to.
+ """
+ options = TranslationUnit_defaultSaveOptions(self)
+ result = int(TranslationUnit_save(self, filename, options))
+ if result != 0:
+ raise TranslationUnitSaveError(result,
+ 'Error saving TranslationUnit.')
+
+ def codeComplete(self, path, line, column, unsaved_files=[], options=0):
"""
Code complete in this translation unit.
@@ -1720,6 +1934,9 @@
and the second should be the contents to be substituted for the
file. The contents may be passed as strings or file objects.
"""
+ if unsaved_files is None:
+ unsaved_files = []
+
unsaved_files_array = 0
if len(unsaved_files):
unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
@@ -1937,11 +2154,29 @@
Cursor_enum_type.restype = Type
Cursor_enum_type.errcheck = Type.from_result
+Cursor_enum_const_decl = lib.clang_getEnumConstantDeclValue
+Cursor_enum_const_decl.argtypes = [Cursor]
+Cursor_enum_const_decl.restype = c_longlong
+
+Cursor_enum_const_decl_unsigned = lib.clang_getEnumConstantDeclUnsignedValue
+Cursor_enum_const_decl_unsigned.argtypes = [Cursor]
+Cursor_enum_const_decl_unsigned.restype = c_ulonglong
+
Cursor_objc_type_encoding = lib.clang_getDeclObjCTypeEncoding
Cursor_objc_type_encoding.argtypes = [Cursor]
Cursor_objc_type_encoding.restype = _CXString
Cursor_objc_type_encoding.errcheck = _CXString.from_result
+Cursor_semantic_parent = lib.clang_getCursorSemanticParent
+Cursor_semantic_parent.argtypes = [Cursor]
+Cursor_semantic_parent.restype = Cursor
+Cursor_semantic_parent.errcheck = Cursor.from_result
+
+Cursor_lexical_parent = lib.clang_getCursorLexicalParent
+Cursor_lexical_parent.argtypes = [Cursor]
+Cursor_lexical_parent.restype = Cursor
+Cursor_lexical_parent.errcheck = Cursor.from_result
+
Cursor_visit_callback = CFUNCTYPE(c_int, Cursor, Cursor, py_object)
Cursor_visit = lib.clang_visitChildren
Cursor_visit.argtypes = [Cursor, Cursor_visit_callback, py_object]
@@ -2068,6 +2303,14 @@
TranslationUnit_includes_callback,
py_object]
+TranslationUnit_defaultSaveOptions = lib.clang_defaultSaveOptions
+TranslationUnit_defaultSaveOptions.argtypes = [TranslationUnit]
+TranslationUnit_defaultSaveOptions.restype = c_uint
+
+TranslationUnit_save = lib.clang_saveTranslationUnit
+TranslationUnit_save.argtypes = [TranslationUnit, c_char_p, c_uint]
+TranslationUnit_save.restype = c_int
+
# File Functions
File_getFile = lib.clang_getFile
File_getFile.argtypes = [TranslationUnit, c_char_p]
@@ -2119,8 +2362,18 @@
_clang_getCompletionPriority.restype = c_int
-###
-
-__all__ = ['Index', 'TranslationUnit', 'Cursor', 'CursorKind', 'Type', 'TypeKind',
- 'Diagnostic', 'FixIt', 'CodeCompletionResults', 'SourceRange',
- 'SourceLocation', 'File']
+__all__ = [
+ 'CodeCompletionResults',
+ 'CursorKind',
+ 'Cursor',
+ 'Diagnostic',
+ 'File',
+ 'FixIt',
+ 'Index',
+ 'SourceLocation',
+ 'SourceRange',
+ 'TranslationUnitLoadError',
+ 'TranslationUnit',
+ 'TypeKind',
+ 'Type',
+]
Modified: cfe/branches/tooling/bindings/python/tests/cindex/test_cursor.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/bindings/python/tests/cindex/test_cursor.py?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/bindings/python/tests/cindex/test_cursor.py (original)
+++ cfe/branches/tooling/bindings/python/tests/cindex/test_cursor.py Tue May 8 03:47:31 2012
@@ -1,6 +1,7 @@
from clang.cindex import CursorKind
from clang.cindex import TypeKind
from .util import get_cursor
+from .util import get_cursors
from .util import get_tu
kInput = """\
@@ -75,6 +76,30 @@
underlying = typedef.underlying_typedef_type
assert underlying.kind == TypeKind.INT
+kParentTest = """\
+ class C {
+ void f();
+ }
+
+ void C::f() { }
+ """
+def test_semantic_parent():
+ tu = get_tu(kParentTest, 'cpp')
+ curs = get_cursors(tu, 'f')
+ decl = get_cursor(tu, 'C')
+ assert(len(curs) == 2)
+ assert(curs[0].semantic_parent == curs[1].semantic_parent)
+ assert(curs[0].semantic_parent == decl)
+
+def test_lexical_parent():
+ tu = get_tu(kParentTest, 'cpp')
+ curs = get_cursors(tu, 'f')
+ decl = get_cursor(tu, 'C')
+ assert(len(curs) == 2)
+ assert(curs[0].lexical_parent != curs[1].lexical_parent)
+ assert(curs[0].lexical_parent == decl)
+ assert(curs[1].lexical_parent == tu.cursor)
+
def test_enum_type():
tu = get_tu('enum TEST { FOO=1, BAR=2 };')
enum = get_cursor(tu, 'TEST')
@@ -84,9 +109,66 @@
enum_type = enum.enum_type
assert enum_type.kind == TypeKind.UINT
+def test_enum_type_cpp():
+ tu = get_tu('enum TEST : long long { FOO=1, BAR=2 };', lang="cpp")
+ enum = get_cursor(tu, 'TEST')
+ assert enum is not None
+
+ assert enum.kind == CursorKind.ENUM_DECL
+ assert enum.enum_type.kind == TypeKind.LONGLONG
+
def test_objc_type_encoding():
tu = get_tu('int i;', lang='objc')
i = get_cursor(tu, 'i')
assert i is not None
assert i.objc_type_encoding == 'i'
+
+def test_enum_values():
+ tu = get_tu('enum TEST { SPAM=1, EGG, HAM = EGG * 20};')
+ enum = get_cursor(tu, 'TEST')
+ assert enum is not None
+
+ assert enum.kind == CursorKind.ENUM_DECL
+
+ enum_constants = list(enum.get_children())
+ assert len(enum_constants) == 3
+
+ spam, egg, ham = enum_constants
+
+ assert spam.kind == CursorKind.ENUM_CONSTANT_DECL
+ assert spam.enum_value == 1
+ assert egg.kind == CursorKind.ENUM_CONSTANT_DECL
+ assert egg.enum_value == 2
+ assert ham.kind == CursorKind.ENUM_CONSTANT_DECL
+ assert ham.enum_value == 40
+
+def test_enum_values_cpp():
+ tu = get_tu('enum TEST : long long { SPAM = -1, HAM = 0x10000000000};', lang="cpp")
+ enum = get_cursor(tu, 'TEST')
+ assert enum is not None
+
+ assert enum.kind == CursorKind.ENUM_DECL
+
+ enum_constants = list(enum.get_children())
+ assert len(enum_constants) == 2
+
+ spam, ham = enum_constants
+
+ assert spam.kind == CursorKind.ENUM_CONSTANT_DECL
+ assert spam.enum_value == -1
+ assert ham.kind == CursorKind.ENUM_CONSTANT_DECL
+ assert ham.enum_value == 0x10000000000
+
+def test_annotation_attribute():
+ tu = get_tu('int foo (void) __attribute__ ((annotate("here be annotation attribute")));')
+
+ foo = get_cursor(tu, 'foo')
+ assert foo is not None
+
+ for c in foo.get_children():
+ if c.kind == CursorKind.ANNOTATE_ATTR:
+ assert c.displayname == "here be annotation attribute"
+ break
+ else:
+ assert False, "Couldn't find annotation"
Modified: cfe/branches/tooling/bindings/python/tests/cindex/test_translation_unit.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/bindings/python/tests/cindex/test_translation_unit.py?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/bindings/python/tests/cindex/test_translation_unit.py (original)
+++ cfe/branches/tooling/bindings/python/tests/cindex/test_translation_unit.py Tue May 8 03:47:31 2012
@@ -1,42 +1,43 @@
-from clang.cindex import *
+from clang.cindex import CursorKind
+from clang.cindex import Cursor
+from clang.cindex import Index
+from clang.cindex import TranslationUnitSaveError
+from clang.cindex import TranslationUnit
+from .util import get_cursor
+from .util import get_tu
import os
kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
def test_spelling():
path = os.path.join(kInputsDir, 'hello.cpp')
- index = Index.create()
- tu = index.parse(path)
+ tu = TranslationUnit.from_source(path)
assert tu.spelling == path
def test_cursor():
path = os.path.join(kInputsDir, 'hello.cpp')
- index = Index.create()
- tu = index.parse(path)
+ tu = get_tu(path)
c = tu.cursor
assert isinstance(c, Cursor)
assert c.kind is CursorKind.TRANSLATION_UNIT
def test_parse_arguments():
path = os.path.join(kInputsDir, 'parse_arguments.c')
- index = Index.create()
- tu = index.parse(path, ['-DDECL_ONE=hello', '-DDECL_TWO=hi'])
+ tu = TranslationUnit.from_source(path, ['-DDECL_ONE=hello', '-DDECL_TWO=hi'])
spellings = [c.spelling for c in tu.cursor.get_children()]
assert spellings[-2] == 'hello'
assert spellings[-1] == 'hi'
def test_reparse_arguments():
path = os.path.join(kInputsDir, 'parse_arguments.c')
- index = Index.create()
- tu = index.parse(path, ['-DDECL_ONE=hello', '-DDECL_TWO=hi'])
+ tu = TranslationUnit.from_source(path, ['-DDECL_ONE=hello', '-DDECL_TWO=hi'])
tu.reparse()
spellings = [c.spelling for c in tu.cursor.get_children()]
assert spellings[-2] == 'hello'
assert spellings[-1] == 'hi'
def test_unsaved_files():
- index = Index.create()
- tu = index.parse('fake.c', ['-I./'], unsaved_files = [
+ tu = TranslationUnit.from_source('fake.c', ['-I./'], unsaved_files = [
('fake.c', """
#include "fake.h"
int x;
@@ -52,8 +53,7 @@
def test_unsaved_files_2():
import StringIO
- index = Index.create()
- tu = index.parse('fake.c', unsaved_files = [
+ tu = TranslationUnit.from_source('fake.c', unsaved_files = [
('fake.c', StringIO.StringIO('int x;'))])
spellings = [c.spelling for c in tu.cursor.get_children()]
assert spellings[-1] == 'x'
@@ -78,7 +78,76 @@
h3 = os.path.join(kInputsDir, "header3.h")
inc = [(src, h1), (h1, h3), (src, h2), (h2, h3)]
- index = Index.create()
- tu = index.parse(src)
+ tu = TranslationUnit.from_source(src)
for i in zip(inc, tu.get_includes()):
assert eq(i[0], i[1])
+
+def save_tu(tu):
+ """Convenience API to save a TranslationUnit to a file.
+
+ Returns the filename it was saved to.
+ """
+
+ # FIXME Generate a temp file path using system APIs.
+ base = 'TEMP_FOR_TRANSLATIONUNIT_SAVE.c'
+ path = os.path.join(kInputsDir, base)
+
+ # Just in case.
+ if os.path.exists(path):
+ os.unlink(path)
+
+ tu.save(path)
+
+ return path
+
+def test_save():
+ """Ensure TranslationUnit.save() works."""
+
+ tu = get_tu('int foo();')
+
+ path = save_tu(tu)
+ assert os.path.exists(path)
+ assert os.path.getsize(path) > 0
+ os.unlink(path)
+
+def test_save_translation_errors():
+ """Ensure that saving to an invalid directory raises."""
+
+ tu = get_tu('int foo();')
+
+ path = '/does/not/exist/llvm-test.ast'
+ assert not os.path.exists(os.path.dirname(path))
+
+ try:
+ tu.save(path)
+ assert False
+ except TranslationUnitSaveError as ex:
+ expected = TranslationUnitSaveError.ERROR_UNKNOWN
+ assert ex.save_error == expected
+
+def test_load():
+ """Ensure TranslationUnits can be constructed from saved files."""
+
+ tu = get_tu('int foo();')
+ assert len(tu.diagnostics) == 0
+ path = save_tu(tu)
+
+ assert os.path.exists(path)
+ assert os.path.getsize(path) > 0
+
+ tu2 = TranslationUnit.from_ast_file(filename=path)
+ assert len(tu2.diagnostics) == 0
+
+ foo = get_cursor(tu2, 'foo')
+ assert foo is not None
+
+ # Just in case there is an open file descriptor somewhere.
+ del tu2
+
+ os.unlink(path)
+
+def test_index_parse():
+ path = os.path.join(kInputsDir, 'hello.cpp')
+ index = Index.create()
+ tu = index.parse(path)
+ assert isinstance(tu, TranslationUnit)
Modified: cfe/branches/tooling/bindings/python/tests/cindex/test_type.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/bindings/python/tests/cindex/test_type.py?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/bindings/python/tests/cindex/test_type.py (original)
+++ cfe/branches/tooling/bindings/python/tests/cindex/test_type.py Tue May 8 03:47:31 2012
@@ -263,7 +263,7 @@
def test_is_restrict_qualified():
"""Ensure Type.is_restrict_qualified works."""
- tu = get_tu('struct s { void * restrict i; void * j };')
+ tu = get_tu('struct s { void * restrict i; void * j; };')
i = get_cursor(tu, 'i')
j = get_cursor(tu, 'j')
Modified: cfe/branches/tooling/bindings/python/tests/cindex/util.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/bindings/python/tests/cindex/util.py?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/bindings/python/tests/cindex/util.py (original)
+++ cfe/branches/tooling/bindings/python/tests/cindex/util.py Tue May 8 03:47:31 2012
@@ -1,7 +1,7 @@
# This file provides common utility functions for the test suite.
from clang.cindex import Cursor
-from clang.cindex import Index
+from clang.cindex import TranslationUnit
def get_tu(source, lang='c', all_warnings=False):
"""Obtain a translation unit from source and language.
@@ -15,21 +15,20 @@
all_warnings is a convenience argument to enable all compiler warnings.
"""
name = 't.c'
+ args = []
if lang == 'cpp':
name = 't.cpp'
+ args.append('-std=c++11')
elif lang == 'objc':
name = 't.m'
elif lang != 'c':
raise Exception('Unknown language: %s' % lang)
- args = []
if all_warnings:
- args = ['-Wall', '-Wextra']
+ args += ['-Wall', '-Wextra']
- index = Index.create()
- tu = index.parse(name, args=args, unsaved_files=[(name, source)])
- assert tu is not None
- return tu
+ return TranslationUnit.from_source(name, args, unsaved_files=[(name,
+ source)])
def get_cursor(source, spelling):
"""Obtain a cursor from a source object.
@@ -57,9 +56,38 @@
return result
return None
+
+def get_cursors(source, spelling):
+ """Obtain all cursors from a source object with a specific spelling.
+
+ This provides a convenient search mechanism to find all cursors with specific
+ spelling within a source. The first argument can be either a
+ TranslationUnit or Cursor instance.
+
+ If no cursors are found, an empty list is returned.
+ """
+ cursors = []
+ children = []
+ if isinstance(source, Cursor):
+ children = source.get_children()
+ else:
+ # Assume TU
+ children = source.cursor.get_children()
+
+ for cursor in children:
+ if cursor.spelling == spelling:
+ cursors.append(cursor)
+
+ # Recurse into children.
+ cursors.extend(get_cursors(cursor, spelling))
+
+ return cursors
+
+
__all__ = [
'get_cursor',
+ 'get_cursors',
'get_tu',
]
Modified: cfe/branches/tooling/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/docs/LanguageExtensions.html?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/docs/LanguageExtensions.html (original)
+++ cfe/branches/tooling/docs/LanguageExtensions.html Tue May 8 03:47:31 2012
@@ -103,6 +103,11 @@
<li><a href="#__sync_swap">__sync_swap</a></li>
</ul>
</li>
+<li><a href="#non-standard-attributes">Non-standard C++11 Attributes</a>
+<ul>
+ <li><a href="#clang__fallthrough">The <tt>clang::fallthrough</tt> attribute</a></li>
+</ul>
+</li>
<li><a href="#targetspecific">Target-Specific Extensions</a>
<ul>
<li><a href="#x86-specific">X86/X86-64 Language Extensions</a></li>
@@ -1497,6 +1502,54 @@
<li><tt>__c11_atomic_fetch_xor</tt></li>
</ul>
+<!-- ======================================================================= -->
+<h2 id="non-standard-attributes">Non-standard C++11 Attributes</h2>
+<!-- ======================================================================= -->
+
+<p>Clang supports one non-standard C++11 attribute. It resides in the
+<tt>clang</tt> attribute namespace.</p>
+
+<!-- ======================================================================= -->
+<h3 id="clang__fallthrough">The <tt>clang::fallthrough</tt> attribute</h3>
+<!-- ======================================================================= -->
+
+<p>The <tt>clang::fallthrough</tt> attribute is used along with the
+<tt>-Wimplicit-fallthrough</tt> argument to annotate intentional fall-through
+between switch labels. It can only be applied to a null statement placed at a
+point of execution between any statement and the next switch label. It is common
+to mark these places with a specific comment, but this attribute is meant to
+replace comments with a more strict annotation, which can be checked by the
+compiler. This attribute doesn't change semantics of the code and can be used
+wherever an intended fall-through occurs. It is designed to mimic
+control-flow statements like <tt>break;</tt>, so it can be placed in most places
+where <tt>break;</tt> can, but only if there are no statements on the execution
+path between it and the next switch label.</p>
+<p>Here is an example:</p>
+<pre>
+// compile with -Wimplicit-fallthrough
+switch (n) {
+case 33:
+ f();
+case 44: // warning: unannotated fall-through
+ g();
+ <b>[[clang::fallthrough]];</b>
+case 55: // no warning
+ if (x) {
+ h();
+ break;
+ }
+ else {
+ i();
+ <b>[[clang::fallthrough]];</b>
+ }
+case 66: // no warning
+ p();
+ <b>[[clang::fallthrough]];</b> // warning: fallthrough annotation does not directly precede case label
+ q();
+case 77: // warning: unannotated fall-through
+ r();
+}
+</pre>
<!-- ======================================================================= -->
<h2 id="targetspecific">Target-Specific Extensions</h2>
Modified: cfe/branches/tooling/docs/ReleaseNotes.html
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/docs/ReleaseNotes.html?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/docs/ReleaseNotes.html (original)
+++ cfe/branches/tooling/docs/ReleaseNotes.html Tue May 8 03:47:31 2012
@@ -118,8 +118,8 @@
<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
<h4 id="cxx11changes">C++11 Feature Support</h4>
-<p>Clang 3.1 adds support for
-<a href="http://clang.llvm.org/cxx_status.html#cxx11">more of the language
+<p>Clang 3.1 supports
+<a href="http://clang.llvm.org/cxx_status.html#cxx11">most of the language
features</a> added in the latest ISO C++ standard,
<a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=50372">C++ 2011</a>.
Use <code>-std=c++11</code> or <code>-std=gnu++11</code> to enable support for
Modified: cfe/branches/tooling/docs/UsersManual.html
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/docs/UsersManual.html?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/docs/UsersManual.html (original)
+++ cfe/branches/tooling/docs/UsersManual.html Tue May 8 03:47:31 2012
@@ -1092,7 +1092,7 @@
<h4 id="target_os_darwin">Darwin (Mac OS/X)</h4>
<!-- ======================================= -->
-<p>No __thread support, 64-bit ObjC support requires SL tools.</p>
+<p>None</p>
<!-- ======================================= -->
<h4 id="target_os_win32">Windows</h4>
Modified: cfe/branches/tooling/examples/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/examples/CMakeLists.txt?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/examples/CMakeLists.txt (original)
+++ cfe/branches/tooling/examples/CMakeLists.txt Tue May 8 03:47:31 2012
@@ -1,5 +1,5 @@
if(NOT CLANG_BUILD_EXAMPLES)
- set(EXCLUDE_FROM_ALL ON)
+ set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
endif()
add_subdirectory(analyzer-plugin)
Modified: cfe/branches/tooling/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang-c/Index.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang-c/Index.h (original)
+++ cfe/branches/tooling/include/clang-c/Index.h Tue May 8 03:47:31 2012
@@ -132,6 +132,29 @@
*/
CXAvailability_NotAccessible
};
+
+/**
+ * \brief Describes a version number of the form major.minor.subminor.
+ */
+typedef struct CXVersion {
+ /**
+ * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
+ * value indicates that there is no version number at all.
+ */
+ int Major;
+ /**
+ * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
+ * will be negative if no minor version number was provided, e.g., for
+ * version '10'.
+ */
+ int Minor;
+ /**
+ * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
+ * will be negative if no minor or subminor version number was provided,
+ * e.g., in version '10' or '10.7'.
+ */
+ int Subminor;
+} CXVersion;
/**
* \defgroup CINDEX_STRING String manipulation routines
@@ -966,7 +989,7 @@
* passed to the \c clang executable if it were being invoked out-of-process.
* These command-line options will be parsed and will affect how the translation
* unit is parsed. Note that the following options are ignored: '-c',
- * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
+ * '-emit-ast', '-fsyntax-only' (which is the default), and '-o <output file>'.
*
* \param num_unsaved_files the number of unsaved file entries in \p
* unsaved_files.
@@ -1115,7 +1138,7 @@
* passed to the \c clang executable if it were being invoked out-of-process.
* These command-line options will be parsed and will affect how the translation
* unit is parsed. Note that the following options are ignored: '-c',
- * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
+ * '-emit-ast', '-fsyntax-only' (which is the default), and '-o <output file>'.
*
* \param num_command_line_args The number of command-line arguments in
* \p command_line_args.
@@ -2165,7 +2188,8 @@
CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
/**
- * \brief Determine the availability of the entity that this cursor refers to.
+ * \brief Determine the availability of the entity that this cursor refers to,
+ * taking the current target platform into account.
*
* \param cursor The cursor to query.
*
@@ -2175,6 +2199,94 @@
clang_getCursorAvailability(CXCursor cursor);
/**
+ * Describes the availability of a given entity on a particular platform, e.g.,
+ * a particular class might only be available on Mac OS 10.7 or newer.
+ */
+typedef struct CXPlatformAvailability {
+ /**
+ * \brief A string that describes the platform for which this structure
+ * provides availability information.
+ *
+ * Possible values are "ios" or "macosx".
+ */
+ CXString Platform;
+ /**
+ * \brief The version number in which this entity was introduced.
+ */
+ CXVersion Introduced;
+ /**
+ * \brief The version number in which this entity was deprecated (but is
+ * still available).
+ */
+ CXVersion Deprecated;
+ /**
+ * \brief The version number in which this entity was obsoleted, and therefore
+ * is no longer available.
+ */
+ CXVersion Obsoleted;
+ /**
+ * \brief Whether the entity is unconditionally unavailable on this platform.
+ */
+ int Unavailable;
+ /**
+ * \brief An optional message to provide to a user of this API, e.g., to
+ * suggest replacement APIs.
+ */
+ CXString Message;
+} CXPlatformAvailability;
+
+/**
+ * \brief Determine the availability of the entity that this cursor refers to
+ * on any platforms for which availability information is known.
+ *
+ * \param cursor The cursor to query.
+ *
+ * \param always_deprecated If non-NULL, will be set to indicate whether the
+ * entity is deprecated on all platforms.
+ *
+ * \param deprecated_message If non-NULL, will be set to the message text
+ * provided along with the unconditional deprecation of this entity. The client
+ * is responsible for deallocating this string.
+ *
+ * \param always_unavailabile If non-NULL, will be set to indicate whether the
+ * entity is unavailable on all platforms.
+ *
+ * \param unavailable_message If non-NULL, will be set to the message text
+ * provided along with the unconditional unavailability of this entity. The
+ * client is responsible for deallocating this string.
+ *
+ * \param availability If non-NULL, an array of CXPlatformAvailability instances
+ * that will be populated with platform availability information, up to either
+ * the number of platforms for which availability information is available (as
+ * returned by this function) or \c availability_size, whichever is smaller.
+ *
+ * \param availability_size The number of elements available in the
+ * \c availability array.
+ *
+ * \returns The number of platforms (N) for which availability information is
+ * available (which is unrelated to \c availability_size).
+ *
+ * Note that the client is responsible for calling
+ * \c clang_disposeCXPlatformAvailability to free each of the
+ * platform-availability structures returned. There are
+ * \c min(N, availability_size) such structures.
+ */
+CINDEX_LINKAGE int
+clang_getCursorPlatformAvailability(CXCursor cursor,
+ int *always_deprecated,
+ CXString *deprecated_message,
+ int *always_unavailable,
+ CXString *unavailable_message,
+ CXPlatformAvailability *availability,
+ int availability_size);
+
+/**
+ * \brief Free the memory associated with a \c CXPlatformAvailability structure.
+ */
+CINDEX_LINKAGE void
+clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
+
+/**
* \brief Describe the "language" of the entity referred to by a cursor.
*/
CINDEX_LINKAGE enum CXLanguageKind {
Modified: cfe/branches/tooling/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/ASTContext.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/ASTContext.h (original)
+++ cfe/branches/tooling/include/clang/AST/ASTContext.h Tue May 8 03:47:31 2012
@@ -557,6 +557,7 @@
CanQualType BoolTy;
CanQualType CharTy;
CanQualType WCharTy; // [C++ 3.9.1p5], integer type in C99.
+ CanQualType WIntTy; // [C99 7.24.1], integer type unchanged by default promotions.
CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
@@ -929,6 +930,10 @@
/// Used when in C++, as a GCC extension.
QualType getUnsignedWCharType() const;
+ /// getWIntType - In C99, this returns a type compatible with the type
+ /// defined in <stddef.h> as defined by the target.
+ QualType getWIntType() const { return WIntTy; }
+
/// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17)
/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
QualType getPointerDiffType() const;
Modified: cfe/branches/tooling/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/Attr.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/Attr.h (original)
+++ cfe/branches/tooling/include/clang/AST/Attr.h Tue May 8 03:47:31 2012
@@ -147,10 +147,6 @@
typedef SmallVector<Attr*, 2> AttrVec;
typedef SmallVector<const Attr*, 2> ConstAttrVec;
-/// DestroyAttrs - Destroy the contents of an AttrVec.
-inline void DestroyAttrs (AttrVec& V, ASTContext &C) {
-}
-
/// specific_attr_iterator - Iterates over a subrange of an AttrVec, only
/// providing attributes that are of a specifc type.
template <typename SpecificAttr>
Modified: cfe/branches/tooling/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/Decl.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/Decl.h (original)
+++ cfe/branches/tooling/include/clang/AST/Decl.h Tue May 8 03:47:31 2012
@@ -64,9 +64,6 @@
/// \brief Return the TypeLoc wrapper for the type source info.
TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
-
- /// \brief Override the type stored in this TypeSourceInfo. Use with caution!
- void overrideType(QualType T) { Ty = T; }
};
/// TranslationUnitDecl - The top declaration context.
@@ -2606,6 +2603,7 @@
void setCompleteDefinition(bool V) { IsCompleteDefinition = V; }
+ // FIXME: Return StringRef;
const char *getKindName() const {
return TypeWithKeyword::getTagTypeKindName(getTagKind());
}
Modified: cfe/branches/tooling/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/DeclBase.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/DeclBase.h (original)
+++ cfe/branches/tooling/include/clang/AST/DeclBase.h Tue May 8 03:47:31 2012
@@ -15,6 +15,7 @@
#define LLVM_CLANG_AST_DECLBASE_H
#include "clang/AST/Attr.h"
+#include "clang/AST/DeclarationName.h"
#include "clang/AST/Type.h"
#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/PointerUnion.h"
@@ -692,17 +693,18 @@
Decl *Starter;
public:
- typedef Decl* value_type;
- typedef Decl* reference;
- typedef Decl* pointer;
+ typedef Decl value_type;
+ typedef value_type& reference;
+ typedef value_type* pointer;
typedef std::forward_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
redecl_iterator() : Current(0) { }
explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { }
- reference operator*() const { return Current; }
+ reference operator*() const { return *Current; }
pointer operator->() const { return Current; }
+ operator pointer() const { return Current; }
redecl_iterator& operator++() {
assert(Current && "Advancing while iterator has reached end");
@@ -1237,8 +1239,8 @@
}
public:
- typedef SpecificDecl* value_type;
- typedef SpecificDecl* reference;
+ typedef SpecificDecl value_type;
+ typedef SpecificDecl& reference;
typedef SpecificDecl* pointer;
typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
difference_type;
@@ -1258,8 +1260,8 @@
SkipToNextDecl();
}
- reference operator*() const { return cast<SpecificDecl>(*Current); }
- pointer operator->() const { return cast<SpecificDecl>(*Current); }
+ reference operator*() const { return *cast<SpecificDecl>(*Current); }
+ pointer operator->() const { return &**this; }
specific_decl_iterator& operator++() {
++Current;
@@ -1320,7 +1322,7 @@
filtered_decl_iterator() : Current() { }
- /// specific_decl_iterator - Construct a new iterator over a
+ /// filtered_decl_iterator - Construct a new iterator over a
/// subset of the declarations the range [C,
/// end-of-declarations). If A is non-NULL, it is a pointer to a
/// member function of SpecificDecl that should return true for
@@ -1410,7 +1412,9 @@
/// and enumerator names preceding any tag name. Note that this
/// routine will not look into parent contexts.
lookup_result lookup(DeclarationName Name);
- lookup_const_result lookup(DeclarationName Name) const;
+ lookup_const_result lookup(DeclarationName Name) const {
+ return const_cast<DeclContext*>(this)->lookup(Name);
+ }
/// \brief A simplistic name lookup mechanism that performs name lookup
/// into this declaration context without consulting the external source.
@@ -1631,6 +1635,23 @@
}
};
+// simplify_type - Allow clients to treat redecl_iterators just like Decl
+// pointers when using casting operators.
+template<> struct simplify_type< ::clang::Decl::redecl_iterator> {
+ typedef ::clang::Decl *SimpleType;
+ static SimpleType getSimplifiedValue(const ::clang::Decl::redecl_iterator
+ &Val) {
+ return Val;
+ }
+};
+template<> struct simplify_type<const ::clang::Decl::redecl_iterator> {
+ typedef ::clang::Decl *SimpleType;
+ static SimpleType getSimplifiedValue(const ::clang::Decl::redecl_iterator
+ &Val) {
+ return Val;
+ }
+};
+
} // end namespace llvm
#endif
Modified: cfe/branches/tooling/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/DeclCXX.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/DeclCXX.h (original)
+++ cfe/branches/tooling/include/clang/AST/DeclCXX.h Tue May 8 03:47:31 2012
@@ -357,6 +357,9 @@
/// \brief True if there no non-field members declared by the user.
bool HasOnlyCMembers : 1;
+ /// \brief True if any field has an in-class initializer.
+ bool HasInClassInitializer : 1;
+
/// HasTrivialDefaultConstructor - True when, if this class has a default
/// constructor, this default constructor is trivial.
///
@@ -1040,6 +1043,10 @@
/// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
bool isAggregate() const { return data().Aggregate; }
+ /// hasInClassInitializer - Whether this class has any in-class initializers
+ /// for non-static data members.
+ bool hasInClassInitializer() const { return data().HasInClassInitializer; }
+
/// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
/// that is an aggregate that has no non-static non-POD data members, no
/// reference data members, no user-defined copy assignment operator and no
@@ -1091,7 +1098,8 @@
/// defaultedDefaultConstructorIsConstexpr - Whether a defaulted default
/// constructor for this class would be constexpr.
bool defaultedDefaultConstructorIsConstexpr() const {
- return data().DefaultedDefaultConstructorIsConstexpr;
+ return data().DefaultedDefaultConstructorIsConstexpr &&
+ (!isUnion() || hasInClassInitializer());
}
/// defaultedCopyConstructorIsConstexpr - Whether a defaulted copy
@@ -1111,7 +1119,7 @@
bool hasConstexprDefaultConstructor() const {
return data().HasConstexprDefaultConstructor ||
(!data().UserDeclaredConstructor &&
- data().DefaultedDefaultConstructorIsConstexpr && isLiteral());
+ defaultedDefaultConstructorIsConstexpr() && isLiteral());
}
/// hasConstexprCopyConstructor - Whether this class has a constexpr copy
Modified: cfe/branches/tooling/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/DeclTemplate.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/DeclTemplate.h (original)
+++ cfe/branches/tooling/include/clang/AST/DeclTemplate.h Tue May 8 03:47:31 2012
@@ -512,7 +512,8 @@
typedef _SETraits SETraits;
typedef _DeclType DeclType;
- typedef typename llvm::FoldingSet<EntryType>::iterator SetIteratorType;
+ typedef typename llvm::FoldingSetVector<EntryType>::iterator
+ SetIteratorType;
SetIteratorType SetIter;
@@ -541,13 +542,13 @@
};
template <typename EntryType>
- SpecIterator<EntryType> makeSpecIterator(llvm::FoldingSet<EntryType> &Specs,
- bool isEnd) {
+ SpecIterator<EntryType>
+ makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) {
return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
}
template <class EntryType> typename SpecEntryTraits<EntryType>::DeclType*
- findSpecializationImpl(llvm::FoldingSet<EntryType> &Specs,
+ findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
const TemplateArgument *Args, unsigned NumArgs,
void *&InsertPos);
@@ -706,7 +707,7 @@
/// \brief The function template specializations for this function
/// template, including explicit specializations and instantiations.
- llvm::FoldingSet<FunctionTemplateSpecializationInfo> Specializations;
+ llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations;
/// \brief The set of "injected" template arguments used within this
/// function template.
@@ -732,13 +733,14 @@
/// \brief Retrieve the set of function template specializations of this
/// function template.
- llvm::FoldingSet<FunctionTemplateSpecializationInfo> &getSpecializations() {
+ llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
+ getSpecializations() {
return getCommonPtr()->Specializations;
}
/// \brief Add a specialization of this function template.
///
- /// \param InsertPos Insert position in the FoldingSet, must have been
+ /// \param InsertPos Insert position in the FoldingSetVector, must have been
/// retrieved by an earlier call to findSpecialization().
void addSpecialization(FunctionTemplateSpecializationInfo* Info,
void *InsertPos);
@@ -1688,11 +1690,11 @@
/// \brief The class template specializations for this class
/// template, including explicit specializations and instantiations.
- llvm::FoldingSet<ClassTemplateSpecializationDecl> Specializations;
+ llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
/// \brief The class template partial specializations for this class
/// template.
- llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>
+ llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
PartialSpecializations;
/// \brief The injected-class-name type for this class template.
@@ -1710,11 +1712,11 @@
void LoadLazySpecializations();
/// \brief Retrieve the set of specializations of this class template.
- llvm::FoldingSet<ClassTemplateSpecializationDecl> &getSpecializations();
+ llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &getSpecializations();
/// \brief Retrieve the set of partial specializations of this class
/// template.
- llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &
+ llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
getPartialSpecializations();
ClassTemplateDecl(DeclContext *DC, SourceLocation L, DeclarationName Name,
Modified: cfe/branches/tooling/include/clang/AST/DeclarationName.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/DeclarationName.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/DeclarationName.h (original)
+++ cfe/branches/tooling/include/clang/AST/DeclarationName.h Tue May 8 03:47:31 2012
@@ -58,11 +58,14 @@
private:
/// StoredNameKind - The kind of name that is actually stored in the
/// upper bits of the Ptr field. This is only used internally.
+ ///
+ /// Note: The entries here are synchronized with the entries in Selector,
+ /// for efficient translation between the two.
enum StoredNameKind {
StoredIdentifier = 0,
- StoredObjCZeroArgSelector,
- StoredObjCOneArgSelector,
- StoredDeclarationNameExtra,
+ StoredObjCZeroArgSelector = 0x01,
+ StoredObjCOneArgSelector = 0x02,
+ StoredDeclarationNameExtra = 0x03,
PtrMask = 0x03
};
@@ -155,7 +158,13 @@
/// getFETokenInfoAsVoid - Retrieves the front end-specified pointer
/// for this name as a void pointer.
- void *getFETokenInfoAsVoid() const;
+ void *getFETokenInfoAsVoid() const {
+ if (getNameKind() == Identifier)
+ return getAsIdentifierInfo()->getFETokenInfo<void>();
+ return getFETokenInfoAsVoidSlow();
+ }
+
+ void *getFETokenInfoAsVoidSlow() const;
public:
/// DeclarationName - Used to create an empty selector.
@@ -168,7 +177,7 @@
}
// Construct a declaration name from an Objective-C selector.
- DeclarationName(Selector Sel);
+ DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) { }
/// getUsingDirectiveName - Return name for all using-directives.
static DeclarationName getUsingDirectiveName();
@@ -251,7 +260,13 @@
/// getObjCSelector - Get the Objective-C selector stored in this
/// declaration name.
- Selector getObjCSelector() const;
+ Selector getObjCSelector() const {
+ assert((getNameKind() == ObjCZeroArgSelector ||
+ getNameKind() == ObjCOneArgSelector ||
+ getNameKind() == ObjCMultiArgSelector ||
+ Ptr == 0) && "Not a selector!");
+ return Selector(Ptr);
+ }
/// getFETokenInfo/setFETokenInfo - The language front-end is
/// allowed to associate arbitrary metadata with some kinds of
@@ -564,7 +579,9 @@
return clang::DeclarationName::getTombstoneMarker();
}
- static unsigned getHashValue(clang::DeclarationName);
+ static unsigned getHashValue(clang::DeclarationName Name) {
+ return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
+ }
static inline bool
isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
Modified: cfe/branches/tooling/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/ExprCXX.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/ExprCXX.h (original)
+++ cfe/branches/tooling/include/clang/AST/ExprCXX.h Tue May 8 03:47:31 2012
@@ -50,14 +50,18 @@
class CXXOperatorCallExpr : public CallExpr {
/// \brief The overloaded operator.
OverloadedOperatorKind Operator;
+ SourceRange Range;
+ SourceRange getSourceRangeImpl() const LLVM_READONLY;
public:
CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
Expr **args, unsigned numargs, QualType t,
ExprValueKind VK, SourceLocation operatorloc)
: CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
operatorloc),
- Operator(Op) {}
+ Operator(Op) {
+ Range = getSourceRangeImpl();
+ }
explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
CallExpr(C, CXXOperatorCallExprClass, Empty) { }
@@ -65,7 +69,6 @@
/// getOperator - Returns the kind of overloaded operator that this
/// expression refers to.
OverloadedOperatorKind getOperator() const { return Operator; }
- void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
/// getOperatorLoc - Returns the location of the operator symbol in
/// the expression. When @c getOperator()==OO_Call, this is the
@@ -74,12 +77,15 @@
/// bracket.
SourceLocation getOperatorLoc() const { return getRParenLoc(); }
- SourceRange getSourceRange() const LLVM_READONLY;
+ SourceRange getSourceRange() const { return Range; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXOperatorCallExprClass;
}
static bool classof(const CXXOperatorCallExpr *) { return true; }
+
+ friend class ASTStmtReader;
+ friend class ASTStmtWriter;
};
/// CXXMemberCallExpr - Represents a call to a member function that
@@ -112,7 +118,7 @@
/// declaration as that of the class context of the CXXMethodDecl which this
/// function is calling.
/// FIXME: Returns 0 for member pointer call exprs.
- CXXRecordDecl *getRecordDecl();
+ CXXRecordDecl *getRecordDecl() const;
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXMemberCallExprClass;
@@ -369,10 +375,21 @@
return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
}
+ SourceLocation getLocStart() const {
+ if (getLiteralOperatorKind() == LOK_Template)
+ return getRParenLoc();
+ return getArg(0)->getLocStart();
+ }
+ SourceLocation getLocEnd() const { return getRParenLoc(); }
+ SourceRange getSourceRange() const {
+ return SourceRange(getLocStart(), getLocEnd());
+ }
+
+
/// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
/// For a string literal, there may be multiple identical suffixes. This
/// returns the first.
- SourceLocation getUDSuffixLoc() const { return getRParenLoc(); }
+ SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
/// getUDSuffix - Returns the ud-suffix specified for this literal.
const IdentifierInfo *getUDSuffix() const;
Modified: cfe/branches/tooling/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/RecordLayout.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/RecordLayout.h (original)
+++ cfe/branches/tooling/include/clang/AST/RecordLayout.h Tue May 8 03:47:31 2012
@@ -33,18 +33,43 @@
/// ObjCInterfaceDecl. FIXME - Find appropriate name.
/// These objects are managed by ASTContext.
class ASTRecordLayout {
+public:
+ struct VBaseInfo {
+ /// The offset to this virtual base in the complete-object layout
+ /// of this class.
+ CharUnits VBaseOffset;
+
+ private:
+ /// Whether this virtual base requires a vtordisp field in the
+ /// Microsoft ABI. These fields are required for certain operations
+ /// in constructors and destructors.
+ bool HasVtorDisp;
+
+ public:
+ bool hasVtorDisp() const { return HasVtorDisp; }
+
+ VBaseInfo() : HasVtorDisp(false) {}
+
+ VBaseInfo(CharUnits VBaseOffset, bool hasVtorDisp) :
+ VBaseOffset(VBaseOffset), HasVtorDisp(hasVtorDisp) {}
+ };
+
+ typedef llvm::DenseMap<const CXXRecordDecl *, VBaseInfo>
+ VBaseOffsetsMapTy;
+
+private:
/// Size - Size of record in characters.
CharUnits Size;
/// DataSize - Size of record in characters without tail padding.
CharUnits DataSize;
- /// FieldOffsets - Array of field offsets in bits.
- uint64_t *FieldOffsets;
-
// Alignment - Alignment of record in characters.
CharUnits Alignment;
+ /// FieldOffsets - Array of field offsets in bits.
+ uint64_t *FieldOffsets;
+
// FieldCount - Number of fields.
unsigned FieldCount;
@@ -63,11 +88,13 @@
/// any empty subobjects.
CharUnits SizeOfLargestEmptySubobject;
- /// VFPtrOffset - Virtual function table offset (Microsoft-only).
- CharUnits VFPtrOffset;
-
/// VBPtrOffset - Virtual base table offset (Microsoft-only).
CharUnits VBPtrOffset;
+
+ /// HasOwnVFPtr - Does this class provide a virtual function table
+ /// (vtable in Itanium, vftbl in Microsoft) that is independent from
+ /// its base classes?
+ bool HasOwnVFPtr; // TODO: stash this somewhere more efficient
/// PrimaryBase - The primary base info for this record.
llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> PrimaryBase;
@@ -79,7 +106,7 @@
BaseOffsetsMapTy BaseOffsets;
/// VBaseOffsets - Contains a map from vbase classes to their offset.
- BaseOffsetsMapTy VBaseOffsets;
+ VBaseOffsetsMapTy VBaseOffsets;
};
/// CXXInfo - If the record layout is for a C++ record, this will have
@@ -96,7 +123,7 @@
typedef CXXRecordLayoutInfo::BaseOffsetsMapTy BaseOffsetsMapTy;
ASTRecordLayout(const ASTContext &Ctx,
CharUnits size, CharUnits alignment,
- CharUnits vfptroffset, CharUnits vbptroffset,
+ bool hasOwnVFPtr, CharUnits vbptroffset,
CharUnits datasize,
const uint64_t *fieldoffsets, unsigned fieldcount,
CharUnits nonvirtualsize, CharUnits nonvirtualalign,
@@ -104,7 +131,7 @@
const CXXRecordDecl *PrimaryBase,
bool IsPrimaryBaseVirtual,
const BaseOffsetsMapTy& BaseOffsets,
- const BaseOffsetsMapTy& VBaseOffsets);
+ const VBaseOffsetsMapTy& VBaseOffsets);
~ASTRecordLayout() {}
@@ -180,7 +207,7 @@
assert(CXXInfo && "Record layout does not have C++ specific info!");
assert(CXXInfo->VBaseOffsets.count(VBase) && "Did not find base!");
- return CXXInfo->VBaseOffsets[VBase];
+ return CXXInfo->VBaseOffsets[VBase].VBaseOffset;
}
/// getBaseClassOffsetInBits - Get the offset, in bits, for the given
@@ -208,11 +235,16 @@
return CXXInfo->SizeOfLargestEmptySubobject;
}
- /// getVFPtrOffset - Get the offset for virtual function table pointer.
- /// This is only meaningful with the Microsoft ABI.
- CharUnits getVFPtrOffset() const {
+ /// hasOwnVFPtr - Does this class provide its own virtual-function
+ /// table pointer, rather than inheriting one from a primary base
+ /// class? If so, it is at offset zero.
+ ///
+ /// This implies that the ABI has no primary base class, meaning
+ /// that it has no base classes that are suitable under the conditions
+ /// of the ABI.
+ bool hasOwnVFPtr() const {
assert(CXXInfo && "Record layout does not have C++ specific info!");
- return CXXInfo->VFPtrOffset;
+ return CXXInfo->HasOwnVFPtr;
}
/// getVBPtrOffset - Get the offset for virtual base table pointer.
@@ -221,6 +253,11 @@
assert(CXXInfo && "Record layout does not have C++ specific info!");
return CXXInfo->VBPtrOffset;
}
+
+ const VBaseOffsetsMapTy &getVBaseOffsetsMap() const {
+ assert(CXXInfo && "Record layout does not have C++ specific info!");
+ return CXXInfo->VBaseOffsets;
+ }
};
} // end namespace clang
Modified: cfe/branches/tooling/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/RecursiveASTVisitor.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/branches/tooling/include/clang/AST/RecursiveASTVisitor.h Tue May 8 03:47:31 2012
@@ -151,7 +151,8 @@
/// \brief Return whether \param S should be traversed using data recursion
/// to avoid a stack overflow with extreme cases.
bool shouldUseDataRecursionFor(Stmt *S) const {
- return isa<BinaryOperator>(S) || isa<UnaryOperator>(S) || isa<CaseStmt>(S);
+ return isa<BinaryOperator>(S) || isa<UnaryOperator>(S) ||
+ isa<CaseStmt>(S) || isa<CXXOperatorCallExpr>(S);
}
/// \brief Recursively visit a statement or expression, by
@@ -404,18 +405,14 @@
bool TraverseFunctionHelper(FunctionDecl *D);
bool TraverseVarHelper(VarDecl *D);
- bool Walk(Stmt *S);
-
struct EnqueueJob {
Stmt *S;
Stmt::child_iterator StmtIt;
- EnqueueJob(Stmt *S) : S(S), StmtIt() {
- if (Expr *E = dyn_cast_or_null<Expr>(S))
- S = E->IgnoreParens();
- }
+ EnqueueJob(Stmt *S) : S(S), StmtIt() {}
};
bool dataTraverse(Stmt *S);
+ bool dataTraverseNode(Stmt *S, bool &EnqueueChildren);
};
template<typename Derived>
@@ -434,7 +431,12 @@
if (getDerived().shouldUseDataRecursionFor(CurrS)) {
if (job.StmtIt == Stmt::child_iterator()) {
- if (!Walk(CurrS)) return false;
+ bool EnqueueChildren = true;
+ if (!dataTraverseNode(CurrS, EnqueueChildren)) return false;
+ if (!EnqueueChildren) {
+ Queue.pop_back();
+ continue;
+ }
job.StmtIt = CurrS->child_begin();
} else {
++job.StmtIt;
@@ -455,10 +457,18 @@
}
template<typename Derived>
-bool RecursiveASTVisitor<Derived>::Walk(Stmt *S) {
+bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
+ bool &EnqueueChildren) {
+ // Dispatch to the corresponding WalkUpFrom* function only if the derived
+ // class didn't override Traverse* (and thus the traversal is trivial).
+ // The cast here is necessary to work around a bug in old versions of g++.
#define DISPATCH_WALK(NAME, CLASS, VAR) \
- return getDerived().WalkUpFrom##NAME(static_cast<CLASS*>(VAR));
+ if (&RecursiveASTVisitor::Traverse##NAME == \
+ (bool (RecursiveASTVisitor::*)(CLASS*))&Derived::Traverse##NAME) \
+ return getDerived().WalkUpFrom##NAME(static_cast<CLASS*>(VAR)); \
+ EnqueueChildren = false; \
+ return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR));
if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
switch (BinOp->getOpcode()) {
@@ -1390,6 +1400,7 @@
case TSK_Undeclared:
case TSK_ImplicitInstantiation:
TRY_TO(TraverseDecl(SD));
+ break;
// We don't need to do anything on an explicit instantiation
// or explicit specialization because there will be an explicit
Modified: cfe/branches/tooling/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/AST/Type.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/AST/Type.h (original)
+++ cfe/branches/tooling/include/clang/AST/Type.h Tue May 8 03:47:31 2012
@@ -29,6 +29,7 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/Twine.h"
#include "clang/Basic/LLVM.h"
namespace clang {
@@ -412,12 +413,11 @@
}
std::string getAsString() const;
- std::string getAsString(const PrintingPolicy &Policy) const {
- std::string Buffer;
- getAsStringInternal(Buffer, Policy);
- return Buffer;
- }
- void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
+ std::string getAsString(const PrintingPolicy &Policy) const;
+
+ bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
+ void print(raw_ostream &OS, const PrintingPolicy &Policy,
+ bool appendSpaceIfNonEmpty = false) const;
void Profile(llvm::FoldingSetNodeID &ID) const {
ID.AddInteger(Mask);
@@ -634,6 +634,11 @@
/// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
bool isPODType(ASTContext &Context) const;
+ /// isCXX98PODType() - Return true if this is a POD type according to the
+ /// rules of the C++98 standard, regardless of the current compilation's
+ /// language.
+ bool isCXX98PODType(ASTContext &Context) const;
+
/// isCXX11PODType() - Return true if this is a POD type according to the
/// more relaxed rules of the C++11 standard, regardless of the current
/// compilation's language.
@@ -824,11 +829,20 @@
}
static std::string getAsString(const Type *ty, Qualifiers qs);
- std::string getAsString(const PrintingPolicy &Policy) const {
- std::string S;
- getAsStringInternal(S, Policy);
- return S;
- }
+ std::string getAsString(const PrintingPolicy &Policy) const;
+
+ void print(raw_ostream &OS, const PrintingPolicy &Policy,
+ const Twine &PlaceHolder = Twine()) const {
+ print(split(), OS, Policy, PlaceHolder);
+ }
+ static void print(SplitQualType split, raw_ostream &OS,
+ const PrintingPolicy &policy, const Twine &PlaceHolder) {
+ return print(split.Ty, split.Quals, OS, policy, PlaceHolder);
+ }
+ static void print(const Type *ty, Qualifiers qs,
+ raw_ostream &OS, const PrintingPolicy &policy,
+ const Twine &PlaceHolder);
+
void getAsStringInternal(std::string &Str,
const PrintingPolicy &Policy) const {
return getAsStringInternal(split(), Str, Policy);
@@ -841,6 +855,27 @@
std::string &out,
const PrintingPolicy &policy);
+ class StreamedQualTypeHelper {
+ const QualType &T;
+ const PrintingPolicy &Policy;
+ const Twine &PlaceHolder;
+ public:
+ StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy,
+ const Twine &PlaceHolder)
+ : T(T), Policy(Policy), PlaceHolder(PlaceHolder) { }
+
+ friend raw_ostream &operator<<(raw_ostream &OS,
+ const StreamedQualTypeHelper &SQT) {
+ SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder);
+ return OS;
+ }
+ };
+
+ StreamedQualTypeHelper stream(const PrintingPolicy &Policy,
+ const Twine &PlaceHolder = Twine()) const {
+ return StreamedQualTypeHelper(*this, Policy, PlaceHolder);
+ }
+
void dump(const char *s) const;
void dump() const;
@@ -1752,7 +1787,13 @@
}
Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
- const char *getName(const PrintingPolicy &Policy) const;
+ StringRef getName(const PrintingPolicy &Policy) const;
+ const char *getNameAsCString(const PrintingPolicy &Policy) const {
+ // The StringRef is null-terminated.
+ StringRef str = getName(Policy);
+ assert(!str.empty() && str.data()[str.size()] == '\0');
+ return str.data();
+ }
bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }
@@ -2928,8 +2969,11 @@
bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }
+ // FIXME: Remove the string version.
void printExceptionSpecification(std::string &S,
PrintingPolicy Policy) const;
+ void printExceptionSpecification(raw_ostream &OS,
+ PrintingPolicy Policy) const;
static bool classof(const Type *T) {
return T->getTypeClass() == FunctionProto;
@@ -3582,6 +3626,7 @@
/// \brief Print a template argument list, including the '<' and '>'
/// enclosing the template arguments.
+ // FIXME: remove the string ones.
static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
unsigned NumArgs,
const PrintingPolicy &Policy,
@@ -3594,6 +3639,23 @@
static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
const PrintingPolicy &Policy);
+ /// \brief Print a template argument list, including the '<' and '>'
+ /// enclosing the template arguments.
+ static void PrintTemplateArgumentList(raw_ostream &OS,
+ const TemplateArgument *Args,
+ unsigned NumArgs,
+ const PrintingPolicy &Policy,
+ bool SkipBrackets = false);
+
+ static void PrintTemplateArgumentList(raw_ostream &OS,
+ const TemplateArgumentLoc *Args,
+ unsigned NumArgs,
+ const PrintingPolicy &Policy);
+
+ static void PrintTemplateArgumentList(raw_ostream &OS,
+ const TemplateArgumentListInfo &,
+ const PrintingPolicy &Policy);
+
/// True if this template specialization type matches a current
/// instantiation in the context in which it is found.
bool isCurrentInstantiation() const {
Modified: cfe/branches/tooling/include/clang/Analysis/Analyses/FormatString.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Analysis/Analyses/FormatString.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Analysis/Analyses/FormatString.h (original)
+++ cfe/branches/tooling/include/clang/Analysis/Analyses/FormatString.h Tue May 8 03:47:31 2012
@@ -175,6 +175,7 @@
switch (kind) {
case PrintErrno:
assert(IsPrintf);
+ return false;
case PercentArg:
return false;
default:
Modified: cfe/branches/tooling/include/clang/Analysis/AnalysisContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Analysis/AnalysisContext.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Analysis/AnalysisContext.h (original)
+++ cfe/branches/tooling/include/clang/Analysis/AnalysisContext.h Tue May 8 03:47:31 2012
@@ -73,9 +73,6 @@
const Decl *D;
- // TranslationUnit is NULL if we don't have multiple translation units.
- idx::TranslationUnit *TU;
-
OwningPtr<CFG> cfg, completeCFG;
OwningPtr<CFGStmtMap> cfgStmtMap;
@@ -98,12 +95,10 @@
public:
AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
- const Decl *D,
- idx::TranslationUnit *TU);
+ const Decl *D);
AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
const Decl *D,
- idx::TranslationUnit *TU,
const CFG::BuildOptions &BuildOptions);
~AnalysisDeclContext();
@@ -111,8 +106,6 @@
ASTContext &getASTContext() { return D->getASTContext(); }
const Decl *getDecl() const { return D; }
- idx::TranslationUnit *getTranslationUnit() const { return TU; }
-
/// Return the build options used to construct the CFG.
CFG::BuildOptions &getCFGBuildOptions() {
return cfgBuildOptions;
@@ -212,10 +205,6 @@
AnalysisDeclContext *getAnalysisDeclContext() const { return Ctx; }
- idx::TranslationUnit *getTranslationUnit() const {
- return Ctx->getTranslationUnit();
- }
-
const LocationContext *getParent() const { return Parent; }
bool isParentOf(const LocationContext *LC) const;
@@ -383,7 +372,7 @@
~AnalysisDeclContextManager();
- AnalysisDeclContext *getContext(const Decl *D, idx::TranslationUnit *TU = 0);
+ AnalysisDeclContext *getContext(const Decl *D);
bool getUseUnoptimizedCFG() const {
return !cfgBuildOptions.PruneTriviallyFalseEdges;
@@ -402,9 +391,8 @@
}
// Get the top level stack frame.
- const StackFrameContext *getStackFrame(Decl const *D,
- idx::TranslationUnit *TU) {
- return LocContexts.getStackFrame(getContext(D, TU), 0, 0, 0, 0);
+ const StackFrameContext *getStackFrame(const Decl *D) {
+ return LocContexts.getStackFrame(getContext(D), 0, 0, 0, 0);
}
// Get a stack frame with parent.
Modified: cfe/branches/tooling/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Analysis/CFG.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Analysis/CFG.h (original)
+++ cfe/branches/tooling/include/clang/Analysis/CFG.h Tue May 8 03:47:31 2012
@@ -277,6 +277,7 @@
typedef std::reverse_iterator<ImplTy::const_iterator> const_iterator;
typedef ImplTy::iterator reverse_iterator;
typedef ImplTy::const_iterator const_reverse_iterator;
+ typedef ImplTy::const_reference const_reference;
void push_back(CFGElement e, BumpVectorContext &C) { Impl.push_back(e, C); }
reverse_iterator insert(reverse_iterator I, size_t Cnt, CFGElement E,
@@ -284,8 +285,8 @@
return Impl.insert(I, Cnt, E, C);
}
- CFGElement front() const { return Impl.back(); }
- CFGElement back() const { return Impl.front(); }
+ const_reference front() const { return Impl.back(); }
+ const_reference back() const { return Impl.front(); }
iterator begin() { return Impl.rbegin(); }
iterator end() { return Impl.rend(); }
Modified: cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/branches/tooling/include/clang/Analysis/ProgramPoint.h Tue May 8 03:47:31 2012
@@ -40,13 +40,13 @@
BlockEntranceKind,
BlockExitKind,
PreStmtKind,
+ PreStmtPurgeDeadSymbolsKind,
+ PostStmtPurgeDeadSymbolsKind,
PostStmtKind,
PreLoadKind,
PostLoadKind,
PreStoreKind,
PostStoreKind,
- PostStmtPurgeDeadSymbolsKind,
- PreStmtPurgeDeadSymbolsKind,
PostConditionKind,
PostLValueKind,
PostInitializerKind,
@@ -352,11 +352,11 @@
/// \class Represents a point after we ran remove dead bindings BEFORE
/// processing the given statement.
-class PreStmtPurgeDeadSymbols : public PostStmt {
+class PreStmtPurgeDeadSymbols : public StmtPoint {
public:
PreStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L,
const ProgramPointTag *tag = 0)
- : PostStmt(S, PreStmtPurgeDeadSymbolsKind, L, tag) { }
+ : StmtPoint(S, 0, PreStmtPurgeDeadSymbolsKind, L, tag) { }
static bool classof(const ProgramPoint* Location) {
return Location->getKind() == PreStmtPurgeDeadSymbolsKind;
@@ -365,11 +365,11 @@
/// \class Represents a point after we ran remove dead bindings AFTER
/// processing the given statement.
-class PostStmtPurgeDeadSymbols : public PostStmt {
+class PostStmtPurgeDeadSymbols : public StmtPoint {
public:
PostStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L,
const ProgramPointTag *tag = 0)
- : PostStmt(S, PostStmtPurgeDeadSymbolsKind, L, tag) { }
+ : StmtPoint(S, 0, PostStmtPurgeDeadSymbolsKind, L, tag) { }
static bool classof(const ProgramPoint* Location) {
return Location->getKind() == PostStmtPurgeDeadSymbolsKind;
Modified: cfe/branches/tooling/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/Attr.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/Attr.td (original)
+++ cfe/branches/tooling/include/clang/Basic/Attr.td Tue May 8 03:47:31 2012
@@ -95,8 +95,12 @@
bit LateParsed = 0;
// Set to true for attributes which must be instantiated within templates
bit TemplateDependent = 0;
+ // Set to true for attributes that have a corresponding AST node.
+ bit ASTNode = 1;
// Set to true for attributes which have handler in Sema.
bit SemaHandler = 1;
+ // Set to true for attributes that are completely ignored.
+ bit Ignored = 0;
// Any additional text that should be included verbatim in the class.
code AdditionalMembers = [{}];
}
@@ -112,13 +116,19 @@
// Attributes begin here
//
+def AddressSpace : Attr {
+ let Spellings = ["address_space"];
+ let Args = [IntArgument<"AddressSpace">];
+ let ASTNode = 0;
+}
+
def Alias : InheritableAttr {
let Spellings = ["alias"];
let Args = [StringArgument<"Aliasee">];
}
def Aligned : InheritableAttr {
- let Spellings = ["aligned"];
+ let Spellings = ["aligned", "align"];
let Subjects = [NonBitField, NormalVar, Tag];
let Args = [AlignedArgument<"Alignment">];
let Namespaces = ["", "std"];
@@ -162,11 +172,23 @@
} }];
}
+def BaseCheck : Attr {
+ let Spellings = ["base_check"];
+ let ASTNode = 0;
+}
+
def Blocks : InheritableAttr {
let Spellings = ["blocks"];
let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
}
+def Bounded : Attr {
+ let Spellings = ["bounded"];
+ let ASTNode = 0;
+ let SemaHandler = 0;
+ let Ignored = 1;
+}
+
def CarriesDependency : InheritableParamAttr {
let Spellings = ["carries_dependency"];
let Subjects = [ParmVar, Function];
@@ -194,6 +216,11 @@
let Subjects = [Function];
}
+def CFReturnsAutoreleased : Attr {
+ let Spellings = ["cf_returns_autoreleased"];
+ let ASTNode = 0;
+}
+
def CFReturnsRetained : InheritableAttr {
let Spellings = ["cf_returns_retained"];
let Subjects = [ObjCMethod, Function];
@@ -219,7 +246,7 @@
}
def Const : InheritableAttr {
- let Spellings = ["const"];
+ let Spellings = ["const", "__const"];
}
def Constructor : InheritableAttr {
@@ -256,6 +283,12 @@
let Spellings = ["opencl_kernel_function"];
}
+def OpenCLImageAccess : Attr {
+ let Spellings = ["opencl_image_access"];
+ let Args = [IntArgument<"Access">];
+ let ASTNode = 0;
+}
+
def Deprecated : InheritableAttr {
let Spellings = ["deprecated"];
let Args = [StringArgument<"Message">];
@@ -274,6 +307,17 @@
let Spellings = ["dllimport"];
}
+def ExtVectorType : Attr {
+ let Spellings = ["ext_vector_type"];
+ let Args = [ExprArgument<"NumElements">];
+ let ASTNode = 0;
+}
+
+def FallThrough : Attr {
+ let Spellings = ["clang___fallthrough"];
+ let Subjects = [CaseStmt, DefaultStmt];
+}
+
def FastCall : InheritableAttr {
let Spellings = ["fastcall", "__fastcall"];
}
@@ -345,10 +389,28 @@
let SemaHandler = 0;
}
+def Mode : Attr {
+ let Spellings = ["mode"];
+ let Args = [IdentifierArgument<"Mode">];
+ let ASTNode = 0;
+}
+
def Naked : InheritableAttr {
let Spellings = ["naked"];
}
+def NeonPolyVectorType : Attr {
+ let Spellings = ["neon_polyvector_type"];
+ let Args = [IntArgument<"NumElements">];
+ let ASTNode = 0;
+}
+
+def NeonVectorType : Attr {
+ let Spellings = ["neon_vector_type"];
+ let Args = [IntArgument<"NumElements">];
+ let ASTNode = 0;
+}
+
def ReturnsTwice : InheritableAttr {
let Spellings = ["returns_twice"];
}
@@ -542,6 +604,18 @@
let Subjects = [ObjCInterface];
}
+def ObjCGC : Attr {
+ let Spellings = ["objc_gc"];
+ let Args = [IdentifierArgument<"Kind">];
+ let ASTNode = 0;
+}
+
+def ObjCOwnership : Attr {
+ let Spellings = ["objc_ownership"];
+ let Args = [IdentifierArgument<"Kind">];
+ let ASTNode = 0;
+}
+
def ObjCRequiresPropertyDefs : InheritableAttr {
let Spellings = ["objc_requires_property_definitions"];
let Subjects = [ObjCInterface];
@@ -561,6 +635,19 @@
let Subjects = [CXXRecord];
}
+def VectorSize : Attr {
+ let Spellings = ["vector_size"];
+ let Args = [ExprArgument<"NumBytes">];
+ let ASTNode = 0;
+}
+
+def VecTypeHint : Attr {
+ let Spellings = ["vec_type_hint"];
+ let ASTNode = 0;
+ let SemaHandler = 0;
+ let Ignored = 1;
+}
+
def Visibility : InheritableAttr {
let Spellings = ["visibility"];
let Args = [EnumArgument<"Visibility", "VisibilityType",
Modified: cfe/branches/tooling/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/Builtins.def?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/Builtins.def (original)
+++ cfe/branches/tooling/include/clang/Basic/Builtins.def Tue May 8 03:47:31 2012
@@ -725,6 +725,10 @@
LIBBUILTIN(index, "c*cC*i", "f", "strings.h", ALL_LANGUAGES)
LIBBUILTIN(rindex, "c*cC*i", "f", "strings.h", ALL_LANGUAGES)
LIBBUILTIN(bzero, "vv*z", "f", "strings.h", ALL_LANGUAGES)
+// In some systems str[n]casejmp is a macro that expands to _str[n]icmp.
+// We undefine then here to avoid wrong name.
+#undef strcasecmp
+#undef strncasecmp
LIBBUILTIN(strcasecmp, "icC*cC*", "f", "strings.h", ALL_LANGUAGES)
LIBBUILTIN(strncasecmp, "icC*cC*z", "f", "strings.h", ALL_LANGUAGES)
// POSIX unistd.h
@@ -882,7 +886,7 @@
// FIXME: Also declare NSConcreteGlobalBlock and NSConcreteStackBlock.
// Annotation function
-BUILTIN(__builtin_annotation, "UiUicC*", "nc")
+BUILTIN(__builtin_annotation, "v.", "tn")
#undef BUILTIN
#undef LIBBUILTIN
Modified: cfe/branches/tooling/include/clang/Basic/BuiltinsX86.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/BuiltinsX86.def?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/branches/tooling/include/clang/Basic/BuiltinsX86.def Tue May 8 03:47:31 2012
@@ -303,8 +303,6 @@
BUILTIN(__builtin_ia32_palignr128, "V16cV16cV16cIc", "")
BUILTIN(__builtin_ia32_insertps128, "V4fV4fV4fi", "")
-BUILTIN(__builtin_ia32_storelv4si, "vV2i*V2LLi", "")
-
BUILTIN(__builtin_ia32_pblendvb128, "V16cV16cV16cV16c", "")
BUILTIN(__builtin_ia32_pblendw128, "V8sV8sV8sIi", "")
BUILTIN(__builtin_ia32_blendpd, "V2dV2dV2dIi", "")
Modified: cfe/branches/tooling/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/Diagnostic.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/Diagnostic.h (original)
+++ cfe/branches/tooling/include/clang/Basic/Diagnostic.h Tue May 8 03:47:31 2012
@@ -781,13 +781,17 @@
void operator=(const DiagnosticBuilder&); // DO NOT IMPLEMENT
friend class DiagnosticsEngine;
+
+ DiagnosticBuilder()
+ : DiagObj(0), NumArgs(0), NumRanges(0), NumFixits(0), IsActive(false) { }
+
explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
: DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0), IsActive(true) {
assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!");
}
friend class PartialDiagnostic;
-
+
protected:
void FlushCounts() {
DiagObj->NumDiagArgs = NumArgs;
@@ -841,6 +845,11 @@
NumFixits = D.NumFixits;
}
+ /// \brief Retrieve an empty diagnostic builder.
+ static DiagnosticBuilder getEmpty() {
+ return DiagnosticBuilder();
+ }
+
/// Destructor - The dtor emits the diagnostic.
~DiagnosticBuilder() {
Emit();
Modified: cfe/branches/tooling/include/clang/Basic/DiagnosticCommonKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/DiagnosticCommonKinds.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/branches/tooling/include/clang/Basic/DiagnosticCommonKinds.td Tue May 8 03:47:31 2012
@@ -74,6 +74,8 @@
def warn_module_build : Warning<"building module '%0' from source">,
InGroup<ModuleBuild>, DefaultIgnore;
def note_pragma_entered_here : Note<"#pragma entered here">;
+def note_decl_hiding_tag_type : Note<
+ "%1 %0 is hidden by a non-type declaration of %0 here">;
// Sema && Lex
def ext_longlong : Extension<
Modified: cfe/branches/tooling/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/DiagnosticGroups.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/branches/tooling/include/clang/Basic/DiagnosticGroups.td Tue May 8 03:47:31 2012
@@ -96,6 +96,7 @@
def : DiagGroup<"c++0x-compat", [CXX11Compat]>;
def : DiagGroup<"effc++">;
+def DivZero : DiagGroup<"division-by-zero">;
def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
def FourByteMultiChar : DiagGroup<"four-char-constants">;
@@ -145,6 +146,7 @@
def OverlengthStrings : DiagGroup<"overlength-strings">;
def OverloadedVirtual : DiagGroup<"overloaded-virtual">;
def ObjCPropertyImpl : DiagGroup<"objc-property-implementation">;
+def ObjCPropertyNoAttribute : DiagGroup<"objc-property-no-attribute">;
def ObjCMissingSuperCalls : DiagGroup<"objc-missing-super-calls">;
def ObjCRetainBlockProperty : DiagGroup<"objc-noncopy-retain-block-property">;
def ObjCReadonlyPropertyHasSetter : DiagGroup<"objc-readonly-with-setter-property">;
@@ -206,6 +208,7 @@
def CoveredSwitchDefault : DiagGroup<"covered-switch-default">;
def SwitchEnum : DiagGroup<"switch-enum">;
def Switch : DiagGroup<"switch">;
+def ImplicitFallthrough : DiagGroup<"implicit-fallthrough">;
def Trigraphs : DiagGroup<"trigraphs">;
def : DiagGroup<"type-limits">;
Modified: cfe/branches/tooling/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/DiagnosticLexKinds.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/branches/tooling/include/clang/Basic/DiagnosticLexKinds.td Tue May 8 03:47:31 2012
@@ -177,6 +177,7 @@
def warn_bad_character_encoding : ExtWarn<
"illegal character encoding in character literal">,
InGroup<DiagGroup<"invalid-source-encoding">>;
+def err_lexing_string : Error<"failure when lexing a string">;
//===----------------------------------------------------------------------===//
Modified: cfe/branches/tooling/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/DiagnosticParseKinds.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/branches/tooling/include/clang/Basic/DiagnosticParseKinds.td Tue May 8 03:47:31 2012
@@ -311,7 +311,7 @@
def err_templated_using_declaration : Error<
"cannot template a using declaration">;
def err_unexected_colon_in_nested_name_spec : Error<
- "unexpected ':' in nested name specifier">;
+ "unexpected ':' in nested name specifier; did you mean '::'?">;
def err_bool_redeclaration : Error<
"redeclaration of C++ built-in type 'bool'">;
def ext_c11_static_assert : Extension<
@@ -396,6 +396,8 @@
"variable declaration in condition must have an initializer">;
def err_expected_init_in_condition_lparen : Error<
"variable declaration in condition cannot have a parenthesized initializer">;
+def err_extraneous_rparen_in_condition : Error<
+ "extraneous ')' after condition, expected a statement">;
def warn_parens_disambiguated_as_function_decl : Warning<
"parentheses were disambiguated as a function declarator">,
InGroup<VexingParse>;
@@ -410,8 +412,6 @@
"exception specification of '...' is a Microsoft extension">;
def err_dynamic_and_noexcept_specification : Error<
"cannot have both throw() and noexcept() clause on the same function">;
-def err_except_spec_unparsed : Error<
- "unexpected end of exception specification">;
def warn_cxx98_compat_noexcept_decl : Warning<
"noexcept specifications are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
@@ -495,7 +495,7 @@
"a space is required between consecutive right angle brackets (use '> >')">;
def warn_cxx0x_right_shift_in_template_arg : Warning<
"use of right-shift operator ('>>') in template argument will require "
- "parentheses in C++11">;
+ "parentheses in C++11">, InGroup<CXX11Compat>;
def warn_cxx98_compat_two_right_angle_brackets : Warning<
"consecutive right angle brackets are incompatible with C++98 (use '> >')">,
InGroup<CXX98Compat>, DefaultIgnore;
@@ -652,7 +652,8 @@
def err_availability_redundant : Error<
"redundant %0 availability change; only the last specified change will " "be used">;
def warn_availability_and_unavailable : Warning<
- "'unavailable' availability overrides all other availability information">;
+ "'unavailable' availability overrides all other availability information">,
+ InGroup<Availability>;
// Language specific pragmas
// - Generic warnings
Modified: cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/branches/tooling/include/clang/Basic/DiagnosticSemaKinds.td Tue May 8 03:47:31 2012
@@ -14,6 +14,12 @@
let Component = "Sema" in {
let CategoryName = "Semantic Issue" in {
+// For loop analysis
+def warn_variables_not_in_loop_body : Warning<
+ "variable%select{s| %1|s %1 and %2|s %1, %2, and %3|s %1, %2, %3, and %4}0 "
+ "used in loop condition not modified in loop body">,
+ InGroup<DiagGroup<"loop-analysis">>, DefaultIgnore;
+
// Constant expressions
def err_expr_not_ice : Error<
"expression is not an %select{integer|integral}0 constant expression">;
@@ -231,9 +237,13 @@
"using declaration can not refer to namespace">;
def err_using_decl_constructor : Error<
"using declaration can not refer to a constructor">;
-def warn_cxx98_compat_using_decl_constructor : Warning<
- "inherited constructors are incompatible with C++98">,
- InGroup<CXX98Compat>, DefaultIgnore;
+def err_using_decl_constructor_unsupported : Error<
+ "inheriting constructors are not supported">;
+// FIXME: Replace the above error with this warning if support for
+// inheriting constructors is implemented.
+//def warn_cxx98_compat_using_decl_constructor : Warning<
+// "inheriting constructors are incompatible with C++98">,
+// InGroup<CXX98Compat>, DefaultIgnore;
def err_using_decl_destructor : Error<
"using declaration can not refer to a destructor">;
def err_using_decl_template_id : Error<
@@ -438,6 +448,8 @@
"cannot declare class extension for %0 after class implementation">;
def note_implementation_declared : Note<
"class implementation is declared here">;
+def not_while_in_implementation : Note<
+ "detected while default synthesizing properties in class implementation">;
def note_class_declared : Note<
"class is declared here">;
def note_receiver_is_id : Note<
@@ -571,13 +583,15 @@
"property with '%0' attribute must be of object type">;
def warn_objc_property_no_assignment_attribute : Warning<
"no 'assign', 'retain', or 'copy' attribute is specified - "
- "'assign' is assumed">;
+ "'assign' is assumed">,
+ InGroup<ObjCPropertyNoAttribute>;
def warn_objc_isa_use : Warning<
"direct access to objective-c's isa is deprecated "
"in favor of object_setClass() and object_getClass()">,
InGroup<DiagGroup<"deprecated-objc-isa-usage">>;
def warn_objc_property_default_assign_on_object : Warning<
- "default property attribute 'assign' not appropriate for non-gc object">;
+ "default property attribute 'assign' not appropriate for non-GC object">,
+ InGroup<ObjCPropertyNoAttribute>;
def warn_property_attr_mismatch : Warning<
"property attribute in continuation class does not match the primary class">;
def warn_objc_property_copy_missing_on_block : Warning<
@@ -606,6 +620,9 @@
"auto property synthesis will not synthesize property"
" declared in a protocol">,
InGroup<DiagGroup<"objc-protocol-property-synthesis">>;
+def warn_missing_explicit_synthesis : Warning <
+ "auto property synthesis is synthesizing property not explicitly synthesized">,
+ InGroup<DiagGroup<"objc-missing-property-synthesis">>, DefaultIgnore;
def warn_property_getter_owning_mismatch : Warning<
"property declared as returning non-retained objects"
"; getter returning retained objects">;
@@ -663,10 +680,8 @@
"weak %select{receiver|property|implicit property}0 may be "
"unpredictably null in ARC mode">,
InGroup<DiagGroup<"receiver-is-weak">>, DefaultIgnore;
-
-def error_synthesized_ivar_yet_not_supported : Error<
- "instance variable synthesis not yet supported"
- " (need to declare %0 explicitly)">;
+def err_incomplete_synthesized_property : Error<
+ "cannot synthesize property %0 with incomplete type %1">;
def error_property_ivar_type : Error<
"type of property %0 (%1) does not match type of ivar %2 (%3)">;
@@ -1313,10 +1328,8 @@
def warn_delegating_ctor_cycle : Warning<
"constructor for %0 creates a delegation cycle">, DefaultError,
InGroup<DelegatingCtorCycles>;
-def note_it_delegates_to : Note<
- "it delegates to">, InGroup<DelegatingCtorCycles>;
-def note_which_delegates_to : Note<
- "which delegates to">, InGroup<DelegatingCtorCycles>;
+def note_it_delegates_to : Note<"it delegates to">;
+def note_which_delegates_to : Note<"which delegates to">;
// C++11 range-based for loop
def err_for_range_decl_must_be_var : Error<
@@ -1450,6 +1463,8 @@
"Neon vector size must be 64 or 128 bits">;
def err_attribute_argument_not_int : Error<
"'%0' attribute requires integer constant">;
+def err_aligned_attribute_argument_not_int : Error<
+ "'aligned' attribute requires integer constant">;
def err_attribute_argument_not_class : Error<
"%0 attribute requires arguments that are class type or point to class type">;
def err_attribute_first_argument_not_int_or_bool : Error<
@@ -1524,7 +1539,7 @@
def err_undeclared_nsstring : Error<
"cannot box a string value because NSString has not been declared">;
def err_objc_illegal_boxed_expression_type : Error<
- "Illegal type %0 used in a boxed expression">;
+ "illegal type %0 used in a boxed expression">;
def err_undeclared_nsarray : Error<
"NSArray must be available to use Objective-C array literals">;
def err_undeclared_nsdictionary : Error<
@@ -1652,12 +1667,14 @@
// Availability attribute
def warn_availability_unknown_platform : Warning<
- "unknown platform %0 in availability macro">;
+ "unknown platform %0 in availability macro">, InGroup<Availability>;
def warn_availability_version_ordering : Warning<
"feature cannot be %select{introduced|deprecated|obsoleted}0 in %1 version "
"%2 before it was %select{introduced|deprecated|obsoleted}3 in version %4; "
- "attribute ignored">;
-
+ "attribute ignored">, InGroup<Availability>;
+def warn_mismatched_availability: Warning<
+ "availability does not match previous declaration">, InGroup<Availability>;
+
// Thread Safety Attributes
def warn_thread_attribute_ignored : Warning<
"ignoring %0 attribute because its argument is invalid">,
@@ -1705,8 +1722,7 @@
"mutex '%0' is locked exclusively and shared in the same scope">,
InGroup<ThreadSafetyAnalysis>, DefaultIgnore;
def note_lock_exclusive_and_shared : Note<
- "the other lock of mutex '%0' is here">,
- InGroup<ThreadSafetyAnalysis>, DefaultIgnore;
+ "the other lock of mutex '%0' is here">;
def warn_variable_requires_lock : Warning<
"%select{reading|writing}2 variable '%0' requires locking "
"%select{'%1'|'%1' exclusively}2">,
@@ -1815,7 +1831,7 @@
def warn_attribute_protected_visibility :
Warning<"target does not support 'protected' visibility; using 'default'">,
InGroup<DiagGroup<"unsupported-visibility">>;
-def err_mismatched_visibilit: Error<"visibility does not match previous declaration">;
+def err_mismatched_visibility: Error<"visibility does not match previous declaration">;
def note_previous_attribute : Note<"previous attribute is here">;
def err_unknown_machine_mode : Error<"unknown machine mode %0">;
def err_unsupported_machine_mode : Error<"unsupported machine mode %0">;
@@ -2007,7 +2023,7 @@
"candidate template ignored: can't deduce a type for %0 which would "
"make %2 equal %1">;
def note_ovl_candidate_substitution_failure : Note<
- "candidate template ignored: substitution failure %0">;
+ "candidate template ignored: substitution failure%0%1">;
// Note that we don't treat templates differently for this diagnostic.
def note_ovl_candidate_arity : Note<"candidate "
@@ -2893,8 +2909,8 @@
def note_deleted_special_member_class_subobject : Note<
"%select{default constructor|copy constructor|move constructor|"
"copy assignment operator|move assignment operator|destructor}0 of "
- "%select{||||union }4%1 is implicitly deleted because "
- "%select{base class %3|field %3}2 has "
+ "%1 is implicitly deleted because "
+ "%select{base class %3|%select{||||variant }4field %3}2 has "
"%select{no|a deleted|multiple|an inaccessible|a non-trivial}4 "
"%select{%select{default constructor|copy constructor|move constructor|copy "
"assignment operator|move assignment operator|destructor}0|destructor}5"
@@ -2913,8 +2929,8 @@
"copy %select{constructor|assignment operator}0 is implicitly deleted because"
" %1 has a user-declared move %select{constructor|assignment operator}2">;
def note_deleted_assign_field : Note<
- "%select{copy|move}0 assignment operator of %0 is implicitly deleted "
- "because field %1 is of %select{reference|const-qualified}3 type %2">;
+ "%select{copy|move}0 assignment operator of %1 is implicitly deleted "
+ "because field %2 is of %select{reference|const-qualified}4 type %3">;
// This should eventually be an error.
def warn_undefined_internal : Warning<
@@ -3531,14 +3547,18 @@
InGroup<DiagGroup<"extended-offsetof">>;
def warn_offsetof_non_pod_type : ExtWarn<"offset of on non-POD type %0">,
InGroup<InvalidOffsetof>;
+def warn_offsetof_non_standardlayout_type : ExtWarn<
+ "offset of on non-standard-layout type %0">, InGroup<InvalidOffsetof>;
def err_offsetof_bitfield : Error<"cannot compute offset of bit-field %0">;
def warn_floatingpoint_eq : Warning<
"comparing floating point with == or != is unsafe">,
InGroup<DiagGroup<"float-equal">>, DefaultIgnore;
-def warn_division_by_zero : Warning<"division by zero is undefined">;
-def warn_remainder_by_zero : Warning<"remainder by zero is undefined">;
+def warn_division_by_zero : Warning<"division by zero is undefined">,
+ InGroup<DivZero>;
+def warn_remainder_by_zero : Warning<"remainder by zero is undefined">,
+ InGroup<DivZero>;
def warn_shift_negative : Warning<"shift count is negative">,
InGroup<DiagGroup<"shift-count-negative">>;
def warn_shift_gt_typewidth : Warning<"shift count >= width of type">,
@@ -3837,9 +3857,6 @@
"declaration">;
def err_invalid_member_use_in_static_method : Error<
"invalid use of member %0 in static member function">;
-def warn_cxx98_compat_this_outside_method : Warning<
- "use of 'this' outside a non-static member function is incompatible "
- "with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
def err_invalid_qualified_function_type : Error<
"%select{static |non-}0member function %select{of type %2 |}1"
"cannot have '%3' qualifier">;
@@ -5172,9 +5189,11 @@
def err_block_returning_array_function : Error<
"block cannot return %select{array|function}0 type %1">;
-// Builtin annotation string.
-def err_builtin_annotation_not_string_constant : Error<
- "__builtin_annotation requires a non wide string constant">;
+// Builtin annotation
+def err_builtin_annotation_first_arg : Error<
+ "first argument to __builtin_annotation must be an integer">;
+def err_builtin_annotation_second_arg : Error<
+ "second argument to __builtin_annotation must be a non-wide string constant">;
// CFString checking
def err_cfstring_literal_not_string_constant : Error<
@@ -5228,6 +5247,27 @@
"%0 enumeration values not handled in switch: %1, %2, %3...">,
InGroup<Switch>;
+def warn_unannotated_fallthrough : Warning<
+ "unannotated fall-through between switch labels">,
+ InGroup<ImplicitFallthrough>, DefaultIgnore;
+def note_insert_fallthrough_fixit : Note<
+ "insert '[[clang::fallthrough]];' to silence this warning">;
+def note_insert_break_fixit : Note<
+ "insert 'break;' to avoid fall-through">;
+def err_fallthrough_attr_wrong_target : Error<
+ "clang::fallthrough attribute is only allowed on empty statements">,
+ InGroup<IgnoredAttributes>;
+def note_fallthrough_insert_semi_fixit : Note<"did you forget ';'?">;
+def err_fallthrough_attr_outside_switch : Error<
+ "fallthrough annotation is outside switch statement">,
+ InGroup<IgnoredAttributes>;
+def warn_fallthrough_attr_invalid_placement : Warning<
+ "fallthrough annotation does not directly precede switch label">,
+ InGroup<ImplicitFallthrough>;
+def warn_fallthrough_attr_unreachable : Warning<
+ "fallthrough annotation in unreachable code">,
+ InGroup<ImplicitFallthrough>;
+
def warn_unreachable_default : Warning<
"default label in switch which covers all enumeration values">,
InGroup<CoveredSwitchDefault>, DefaultIgnore;
@@ -5260,8 +5300,7 @@
def warn_empty_switch_body : Warning<
"switch statement has empty body">, InGroup<EmptyBody>;
def note_empty_body_on_separate_line : Note<
- "put the semicolon on a separate line to silence this warning">,
- InGroup<EmptyBody>;
+ "put the semicolon on a separate line to silence this warning">;
def err_va_start_used_in_non_variadic_function : Error<
"'va_start' used in function with fixed args">;
Modified: cfe/branches/tooling/include/clang/Basic/DiagnosticSerializationKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/DiagnosticSerializationKinds.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/branches/tooling/include/clang/Basic/DiagnosticSerializationKinds.td Tue May 8 03:47:31 2012
@@ -22,6 +22,8 @@
def err_fe_pch_file_modified : Error<
"file '%0' has been modified since the precompiled header was built">,
DefaultFatal;
+def err_fe_pch_file_overridden : Error<
+ "file '%0' from the precompiled header has been overridden">;
def warn_pch_target_triple : Error<
"PCH file was compiled for the target '%0' but the current translation "
Modified: cfe/branches/tooling/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/FileManager.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/FileManager.h (original)
+++ cfe/branches/tooling/include/clang/Basic/FileManager.h Tue May 8 03:47:31 2012
@@ -226,6 +226,11 @@
void GetUniqueIDMapping(
SmallVectorImpl<const FileEntry *> &UIDToFiles) const;
+ /// \brief Modifies the size and modification time of a previously created
+ /// FileEntry. Use with caution.
+ static void modifyFileEntry(FileEntry *File, off_t Size,
+ time_t ModificationTime);
+
void PrintStats() const;
};
Modified: cfe/branches/tooling/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/IdentifierTable.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/branches/tooling/include/clang/Basic/IdentifierTable.h Tue May 8 03:47:31 2012
@@ -574,9 +574,10 @@
friend class Diagnostic;
enum IdentifierInfoFlag {
- // MultiKeywordSelector = 0.
+ // Empty selector = 0.
ZeroArg = 0x1,
OneArg = 0x2,
+ MultiArg = 0x3,
ArgFlags = ZeroArg|OneArg
};
uintptr_t InfoPtr; // a pointer to the MultiKeywordSelector or IdentifierInfo.
@@ -590,13 +591,18 @@
Selector(MultiKeywordSelector *SI) {
InfoPtr = reinterpret_cast<uintptr_t>(SI);
assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
+ InfoPtr |= MultiArg;
}
IdentifierInfo *getAsIdentifierInfo() const {
- if (getIdentifierInfoFlag())
+ if (getIdentifierInfoFlag() < MultiArg)
return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags);
return 0;
}
+ MultiKeywordSelector *getMultiKeywordSelector() const {
+ return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags);
+ }
+
unsigned getIdentifierInfoFlag() const {
return InfoPtr & ArgFlags;
}
@@ -663,6 +669,7 @@
/// getAsString - Derive the full selector name (e.g. "foo:bar:") and return
/// it as an std::string.
+ // FIXME: Add a print method that uses a raw_ostream.
std::string getAsString() const;
/// getMethodFamily - Derive the conventional family of this method.
Modified: cfe/branches/tooling/include/clang/Basic/PartialDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/PartialDiagnostic.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/PartialDiagnostic.h (original)
+++ cfe/branches/tooling/include/clang/Basic/PartialDiagnostic.h Tue May 8 03:47:31 2012
@@ -179,6 +179,12 @@
}
public:
+ struct NullDiagnostic {};
+ /// \brief Create a null partial diagnostic, which cannot carry a payload,
+ /// and only exists to be swapped with a real partial diagnostic.
+ PartialDiagnostic(NullDiagnostic)
+ : DiagID(0), DiagStorage(0), Allocator(0) { }
+
PartialDiagnostic(unsigned DiagID, StorageAllocator &Allocator)
: DiagID(DiagID), DiagStorage(0), Allocator(&Allocator) { }
@@ -237,6 +243,12 @@
freeStorage();
}
+ void swap(PartialDiagnostic &PD) {
+ std::swap(DiagID, PD.DiagID);
+ std::swap(DiagStorage, PD.DiagStorage);
+ std::swap(Allocator, PD.Allocator);
+ }
+
unsigned getDiagID() const { return DiagID; }
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const {
@@ -283,6 +295,18 @@
DB.AddFixItHint(DiagStorage->FixItHints[i]);
}
+ void EmitToString(DiagnosticsEngine &Diags,
+ llvm::SmallVectorImpl<char> &Buf) const {
+ // FIXME: It should be possible to render a diagnostic to a string without
+ // messing with the state of the diagnostics engine.
+ DiagnosticBuilder DB(Diags.Report(getDiagID()));
+ Emit(DB);
+ DB.FlushCounts();
+ Diagnostic(&Diags).FormatDiagnostic(Buf);
+ DB.Clear();
+ Diags.Clear();
+ }
+
/// \brief Clear out this partial diagnostic, giving it a new diagnostic ID
/// and removing all of its arguments, ranges, and fix-it hints.
void Reset(unsigned DiagID = 0) {
Modified: cfe/branches/tooling/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/SourceManager.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/SourceManager.h (original)
+++ cfe/branches/tooling/include/clang/Basic/SourceManager.h Tue May 8 03:47:31 2012
@@ -21,7 +21,9 @@
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/MemoryBuffer.h"
#include <map>
#include <vector>
@@ -501,9 +503,24 @@
/// files, should report the original file name. Defaults to true.
bool OverridenFilesKeepOriginalName;
- /// \brief Files that have been overriden with the contents from another file.
- llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
+ struct OverriddenFilesInfoTy {
+ /// \brief Files that have been overriden with the contents from another
+ /// file.
+ llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
+ /// \brief Files that were overridden with a memory buffer.
+ llvm::DenseSet<const FileEntry *> OverriddenFilesWithBuffer;
+ };
+ /// \brief Lazily create the object keeping overridden files info, since
+ /// it is uncommonly used.
+ OwningPtr<OverriddenFilesInfoTy> OverriddenFilesInfo;
+
+ OverriddenFilesInfoTy &getOverriddenFilesInfo() {
+ if (!OverriddenFilesInfo)
+ OverriddenFilesInfo.reset(new OverriddenFilesInfoTy);
+ return *OverriddenFilesInfo;
+ }
+
/// MemBufferInfos - Information about various memory buffers that we have
/// read in. All FileEntry* within the stored ContentCache objects are NULL,
/// as they do not refer to a file.
@@ -715,6 +732,23 @@
void overrideFileContents(const FileEntry *SourceFile,
const FileEntry *NewFile);
+ /// \brief Returns true if the file contents have been overridden.
+ bool isFileOverridden(const FileEntry *File) {
+ if (OverriddenFilesInfo) {
+ if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
+ return true;
+ if (OverriddenFilesInfo->OverriddenFiles.find(File) !=
+ OverriddenFilesInfo->OverriddenFiles.end())
+ return true;
+ }
+ return false;
+ }
+
+ /// \brief Disable overridding the contents of a file, previously enabled
+ /// with \see overrideFileContents.
+ /// This should be called before parsing has begun.
+ void disableFileContentsOverride(const FileEntry *File);
+
//===--------------------------------------------------------------------===//
// FileID manipulation methods.
//===--------------------------------------------------------------------===//
Modified: cfe/branches/tooling/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Basic/TokenKinds.def?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Basic/TokenKinds.def (original)
+++ cfe/branches/tooling/include/clang/Basic/TokenKinds.def Tue May 8 03:47:31 2012
@@ -105,7 +105,6 @@
// directive).
TOK(code_completion) // Code completion marker
TOK(cxx_defaultarg_end) // C++ default argument end marker
-TOK(cxx_exceptspec_end) // C++ exception-specification end marker
// C99 6.4.9: Comments.
TOK(comment) // Comment (only in -E -C[C] mode)
Modified: cfe/branches/tooling/include/clang/Driver/CC1Options.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/CC1Options.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/CC1Options.h (original)
+++ cfe/branches/tooling/include/clang/Driver/CC1Options.h Tue May 8 03:47:31 2012
@@ -1,32 +0,0 @@
-//===--- CC1Options.h - Clang CC1 Options Table -----------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef CLANG_DRIVER_CC1OPTIONS_H
-#define CLANG_DRIVER_CC1OPTIONS_H
-
-namespace clang {
-namespace driver {
- class OptTable;
-
-namespace cc1options {
- enum ID {
- OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
- HELPTEXT, METAVAR) OPT_##ID,
-#include "clang/Driver/CC1Options.inc"
- LastOption
-#undef OPTION
- };
-}
-
- OptTable *createCC1OptTable();
-}
-}
-
-#endif
Modified: cfe/branches/tooling/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/CC1Options.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/CC1Options.td (original)
+++ cfe/branches/tooling/include/clang/Driver/CC1Options.td Tue May 8 03:47:31 2012
@@ -11,8 +11,7 @@
//
//===----------------------------------------------------------------------===//
-// Include the common option parsing interfaces.
-include "OptParser.td"
+let Flags = [CC1Option] in {
//===----------------------------------------------------------------------===//
// Target Options
@@ -145,46 +144,12 @@
HelpText<"The compilation directory to embed in the debug info.">;
def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,
HelpText<"The string to embed in the Dwarf debug flags record.">;
-def faddress_sanitizer: Flag<"-faddress-sanitizer">,
- HelpText<"Enable AddressSanitizer instrumentation (memory error detection)">;
-def fthread_sanitizer: Flag<"-fthread-sanitizer">,
- HelpText<"Enable ThreadSanitizer instrumentation (race detection)">;
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 fno_dwarf2_cfi_asm : Flag<"-fno-dwarf2-cfi-asm">,
- HelpText<"Don't use the cfi directives">;
-def fno_dwarf_directory_asm : Flag<"-fno-dwarf-directory-asm">,
- HelpText<"Don't separate directory and filename in .file directives">;
-def fcatch_undefined_behavior : Flag<"-fcatch-undefined-behavior">,
- HelpText<"Generate runtime checks for undefined behavior.">;
-def flimit_debug_info : Flag<"-flimit-debug-info">,
- HelpText<"Limit debug information produced to reduce size of debug binary">;
-def fno_common : Flag<"-fno-common">,
- HelpText<"Compile common globals like normal definitions">;
def no_implicit_float : Flag<"-no-implicit-float">,
HelpText<"Don't generate implicit floating point instructions (x86-only)">;
-def finstrument_functions : Flag<"-finstrument-functions">,
- HelpText<"Generate calls to instrument function entry and exit">;
-def fno_limit_debug_info : Flag<"-fno-limit-debug-info">,
- HelpText<"Do not limit debug information produced to reduce size of debug binary">;
-def fno_merge_all_constants : Flag<"-fno-merge-all-constants">,
- HelpText<"Disallow merging of constants.">;
-def fno_threadsafe_statics : Flag<"-fno-threadsafe-statics">,
- HelpText<"Do not emit code to make initialization of local statics thread safe">;
def fdump_vtable_layouts : Flag<"-fdump-vtable-layouts">,
HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">;
-def ffunction_sections : Flag<"-ffunction-sections">,
- HelpText<"Place each function in its own section (ELF Only)">;
-def fdata_sections : Flag<"-fdata-sections">,
- HelpText<"Place each data in its own section (ELF Only)">;
-def fstrict_enums : Flag<"-fstrict-enums">,
- HelpText<"Enable optimizations based on the strict definition of an enum's "
- "value range.">;
-def ftrap_function_EQ : Joined<"-ftrap-function=">,
- HelpText<"Issue call to specified function rather than a trap instruction">;
-def funroll_loops : Flag<"-funroll-loops">,
- HelpText<"Turn on loop unroller">;
def femit_coverage_notes : Flag<"-femit-coverage-notes">,
HelpText<"Emit a gcov coverage notes file when compiling.">;
def femit_coverage_data: Flag<"-femit-coverage-data">,
@@ -215,66 +180,35 @@
"precision">;
def mfloat_abi : Separate<"-mfloat-abi">,
HelpText<"The float ABI to use">;
-def mno_global_merge : Flag<"-mno-global-merge">,
- HelpText<"Disable merging of globals">;
def mlimit_float_precision : Separate<"-mlimit-float-precision">,
HelpText<"Limit float precision to the given value">;
def mno_exec_stack : Flag<"-mnoexecstack">,
HelpText<"Mark the file as not needing an executable stack">;
def mno_zero_initialized_in_bss : Flag<"-mno-zero-initialized-in-bss">,
HelpText<"Do not put zero initialized data in the BSS">;
-def momit_leaf_frame_pointer : Flag<"-momit-leaf-frame-pointer">,
- HelpText<"Omit frame pointer setup for leaf functions.">;
-def msoft_float : Flag<"-msoft-float">,
- HelpText<"Use software floating point">;
def backend_option : Separate<"-backend-option">,
HelpText<"Additional arguments to forward to LLVM backend (during code gen)">;
def mregparm : Separate<"-mregparm">,
HelpText<"Limit the number of registers available for integer arguments">;
-def mrelax_all : Flag<"-mrelax-all">,
- HelpText<"(integrated-as) Relax all machine instructions">;
def msave_temp_labels : Flag<"-msave-temp-labels">,
HelpText<"(integrated-as) Save temporary labels">;
-def mrtd: Flag<"-mrtd">,
- HelpText<"Make StdCall calling convention the default">;
def mrelocation_model : Separate<"-mrelocation-model">,
HelpText<"The relocation model to use">;
def munwind_tables : Flag<"-munwind-tables">,
HelpText<"Generate unwinding tables for all functions">;
def mconstructor_aliases : Flag<"-mconstructor-aliases">,
HelpText<"Emit complete constructors and destructors as aliases when possible">;
-def mms_bitfields : Flag<"-mms-bitfields">,
- HelpText<"Set the default structure layout to be compatible with the Microsoft compiler standard.">;
-def mstackrealign : Flag<"-mstackrealign">,
- HelpText<"Force realign the stack at entry to every function.">;
-def mstack_alignment : Joined<"-mstack-alignment=">,
- HelpText<"Set the stack alignment">;
def mlink_bitcode_file : Separate<"-mlink-bitcode-file">,
HelpText<"Link the given bitcode file before performing optimizations.">;
-def O : Joined<"-O">, HelpText<"Optimization level">;
-def Os : Flag<"-Os">, HelpText<"Optimize for size">;
-def Oz : Flag<"-Oz">, HelpText<"Optimize for size, regardless of performance">;
-def pg : Flag<"-pg">, HelpText<"Enable mcount instrumentation">;
//===----------------------------------------------------------------------===//
// Dependency Output Options
//===----------------------------------------------------------------------===//
-def dependency_file : Separate<"-dependency-file">,
- HelpText<"Filename (or -) to write dependency output to">;
-def dependency_dot : Separate<"-dependency-dot">,
- HelpText<"Filename to write DOT-formatted header dependencies to">;
def sys_header_deps : Flag<"-sys-header-deps">,
HelpText<"Include system headers in dependency output">;
def header_include_file : Separate<"-header-include-file">,
HelpText<"Filename (or -) to write header include output to">;
-def H : Flag<"-H">,
- HelpText<"Show header includes and nesting depth">;
-def MQ : Separate<"-MQ">, HelpText<"Specify target to quote for dependency">;
-def MT : Separate<"-MT">, HelpText<"Specify target for dependency">;
-def MP : Flag<"-MP">,
- HelpText<"Create phony target for each dependency (other than main file)">;
-def MG : Flag<"-MG">, HelpText<"Add missing headers to dependency list">;
//===----------------------------------------------------------------------===//
// Diagnostic Options
@@ -288,44 +222,11 @@
def diagnostic_serialized_file : Separate<"-serialize-diagnostic-file">,
MetaVarName<"<filename>">,
HelpText<"File for serializing diagnostics in a binary format">;
-def fno_show_column : Flag<"-fno-show-column">,
- HelpText<"Do not include column number on diagnostics">;
-def fshow_column : Flag<"-fshow-column">,
- HelpText<"Include column number on diagnostics">;
-def fno_show_source_location : Flag<"-fno-show-source-location">,
- HelpText<"Do not include source location information with diagnostics">;
-def fshow_overloads_EQ : Joined<"-fshow-overloads=">,
- HelpText<"Which overload candidates to show when overload resolution fails: "
- "best|all; defaults to all">;
-def fno_caret_diagnostics : Flag<"-fno-caret-diagnostics">,
- HelpText<"Do not include source line and caret with diagnostics">;
-def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">,
- HelpText<"Do not include fixit information in diagnostics">;
-def fno_diagnostics_show_note_include_stack :
- Flag<"-fno-diagnostics-show-note-include-stack">,
- HelpText<"Display include stacks for diagnostic notes">;
-def w : Flag<"-w">, HelpText<"Suppress all warnings">;
-def pedantic : Flag<"-pedantic">;
-def pedantic_errors : Flag<"-pedantic-errors">;
-
-// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The
-// driver has stripped off -Wa,foo etc. The driver has also translated -W to
-// -Wextra, so we don't need to worry about it.
-def W : Joined<"-W">;
-
-def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-range-info">,
- HelpText<"Print source range spans in numeric form">;
-def fdiagnostics_parseable_fixits : Flag<"-fdiagnostics-parseable-fixits">,
- HelpText<"Print fix-its in machine parseable form">;
-def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">,
- HelpText<"Print option name with mappable diagnostics">;
+
def fdiagnostics_format : Separate<"-fdiagnostics-format">,
HelpText<"Change diagnostic formatting to match IDE and command line tools">;
def fdiagnostics_show_category : Separate<"-fdiagnostics-show-category">,
HelpText<"Print diagnostic category">;
-def fdiagnostics_show_note_include_stack :
- Flag<"-fdiagnostics-show-note-include-stack">,
- HelpText<"Display include stacks for diagnostic notes">;
def ftabstop : Separate<"-ftabstop">, MetaVarName<"<N>">,
HelpText<"Set the tab stop distance.">;
def ferror_limit : Separate<"-ferror-limit">, MetaVarName<"<N>">,
@@ -338,12 +239,8 @@
HelpText<"Set the maximum number of entries to print in a constexpr evaluation backtrace (0 = no limit).">;
def fmessage_length : Separate<"-fmessage-length">, MetaVarName<"<N>">,
HelpText<"Format message diagnostics so that they fit within N columns or fewer, when possible.">;
-def fcolor_diagnostics : Flag<"-fcolor-diagnostics">,
- HelpText<"Use colors in diagnostics">;
def Wno_rewrite_macros : Flag<"-Wno-rewrite-macros">,
HelpText<"Silence ObjC rewriting warnings">;
-def verify : Flag<"-verify">,
- HelpText<"Verify emitted diagnostics and warnings">;
//===----------------------------------------------------------------------===//
// Frontend Options
@@ -372,11 +269,6 @@
HelpText<"Do not include global declarations in code-completion results.">;
def disable_free : Flag<"-disable-free">,
HelpText<"Disable freeing of memory on exit">;
-def help : Flag<"-help">,
- HelpText<"Print this help text">;
-def _help : Flag<"--help">, Alias<help>;
-def x : Separate<"-x">, HelpText<"Input language type">;
-def o : Separate<"-o">, MetaVarName<"<path>">, HelpText<"Specify output file">;
def load : Separate<"-load">, MetaVarName<"<dsopath>">,
HelpText<"Load the named plugin (dynamic shared object)">;
def plugin : Separate<"-plugin">, MetaVarName<"<name>">,
@@ -390,15 +282,11 @@
HelpText<"The directory which holds the compiler resource files">;
def version : Flag<"-version">,
HelpText<"Print the compiler version">;
-def _version : Flag<"--version">, Alias<version>;
-def Action_Group : OptionGroup<"<action group>">;
let Group = Action_Group in {
def Eonly : Flag<"-Eonly">,
HelpText<"Just run preprocessor, no output (for timings)">;
-def E : Flag<"-E">,
- HelpText<"Run preprocessor, emit preprocessed file">;
def dump_raw_tokens : Flag<"-dump-raw-tokens">,
HelpText<"Lex file in raw mode and dump raw tokens">;
def analyze : Flag<"-analyze">,
@@ -407,8 +295,6 @@
HelpText<"Run preprocessor, dump internal rep of tokens">;
def init_only : Flag<"-init-only">,
HelpText<"Only execute frontend initialization">;
-def fsyntax_only : Flag<"-fsyntax-only">,
- HelpText<"Run parser and perform semantic analysis">;
def fixit : Flag<"-fixit">,
HelpText<"Apply fix-it advice to the input source">;
def fixit_EQ : Joined<"-fixit=">,
@@ -434,10 +320,6 @@
HelpText<"Generate pre-tokenized header file">;
def emit_pch : Flag<"-emit-pch">,
HelpText<"Generate pre-compiled header file">;
-def S : Flag<"-S">,
- HelpText<"Emit native assembly code">;
-def emit_llvm : Flag<"-emit-llvm">,
- HelpText<"Build ASTs then convert to LLVM, emit .ll file">;
def emit_llvm_bc : Flag<"-emit-llvm-bc">,
HelpText<"Build ASTs then convert to LLVM, emit .bc file">;
def emit_llvm_only : Flag<"-emit-llvm-only">,
@@ -448,8 +330,6 @@
HelpText<"Emit native object files">;
def rewrite_test : Flag<"-rewrite-test">,
HelpText<"Rewriter playground">;
-def rewrite_objc : Flag<"-rewrite-objc">,
- HelpText<"Rewrite ObjC into C (code rewriter example)">;
def rewrite_macros : Flag<"-rewrite-macros">,
HelpText<"Expand macros without full preprocessing">;
def migrate : Flag<"-migrate">,
@@ -464,27 +344,11 @@
HelpText<"Apply modifications to files to conform to ARC">;
def arcmt_migrate : Flag<"-arcmt-migrate">,
HelpText<"Apply modifications and produces temporary files that conform to ARC">;
-def arcmt_migrate_report_output : Separate<"-arcmt-migrate-report-output">,
- HelpText<"Output path for the plist report">;
-def arcmt_migrate_emit_arc_errors : Flag<"-arcmt-migrate-emit-errors">,
- HelpText<"Emit ARC errors even if the migrator can fix them">;
-
-def objcmt_migrate_literals : Flag<"-objcmt-migrate-literals">,
- HelpText<"Enable migration to modern ObjC literals">;
-def objcmt_migrate_subscripting : Flag<"-objcmt-migrate-subscripting">,
- HelpText<"Enable migration to modern ObjC subscripting">;
-
-def working_directory : JoinedOrSeparate<"-working-directory">,
- HelpText<"Resolve file paths relative to the specified directory">;
-def working_directory_EQ : Joined<"-working-directory=">,
- Alias<working_directory>;
def relocatable_pch : Flag<"-relocatable-pch">,
HelpText<"Whether to build a relocatable precompiled header">;
def print_stats : Flag<"-print-stats">,
HelpText<"Print performance metrics and statistics">;
-def ftime_report : Flag<"-ftime-report">,
- HelpText<"Print the amount of time each phase of compilation takes">;
def fdump_record_layouts : Flag<"-fdump-record-layouts">,
HelpText<"Dump record layout information">;
def fdump_record_layouts_simple : Flag<"-fdump-record-layouts-simple">,
@@ -498,11 +362,6 @@
def fixit_to_temp : Flag<"-fixit-to-temporary">,
HelpText<"Apply fix-it changes to temporary files">;
-// Generic forwarding to LLVM options. This should only be used for debugging
-// and experimental features.
-def mllvm : Separate<"-mllvm">,
- HelpText<"Additional arguments to forward to LLVM's option processing">;
-
def foverride_record_layout_EQ : Joined<"-foverride-record-layout=">,
HelpText<"Override record layouts with those in the given file">;
@@ -510,135 +369,37 @@
// Language Options
//===----------------------------------------------------------------------===//
-def fno_builtin : Flag<"-fno-builtin">,
- HelpText<"Disable implicit builtin knowledge of functions">;
-def faltivec : Flag<"-faltivec">,
- HelpText<"Enable AltiVec vector initializer syntax">;
-def fno_access_control : Flag<"-fno-access-control">,
- HelpText<"Disable C++ access control">;
-def fno_assume_sane_operator_new : Flag<"-fno-assume-sane-operator-new">,
- HelpText<"Don't assume that C++'s global operator new can't alias any pointer">;
-def fgnu_keywords : Flag<"-fgnu-keywords">,
- HelpText<"Allow GNU-extension keywords regardless of language standard">;
-def fgnu89_inline : Flag<"-fgnu89-inline">,
- HelpText<"Use the gnu89 inline semantics">;
-def fno_inline : Flag<"-fno-inline">,
- HelpText<"Disable use of the inline keyword">;
-def fno_inline_functions : Flag<"-fno-inline-functions">,
- HelpText<"Disable automatic function inlining">;
-def fno_gnu_keywords : Flag<"-fno-gnu-keywords">,
- HelpText<"Disallow GNU-extension keywords regardless of language standard">;
-def fdollars_in_identifiers : Flag<"-fdollars-in-identifiers">,
- HelpText<"Allow '$' in identifiers">;
-def fno_dollars_in_identifiers : Flag<"-fno-dollars-in-identifiers">,
- HelpText<"Disallow '$' in identifiers">;
-def femit_all_decls : Flag<"-femit-all-decls">,
- HelpText<"Emit all declarations, even if unused">;
-def fblocks : Flag<"-fblocks">,
- HelpText<"Enable the 'blocks' language feature">;
def fblocks_runtime_optional : Flag<"-fblocks-runtime-optional">,
HelpText<"Weakly link in the blocks runtime">;
-def fheinous_gnu_extensions : Flag<"-fheinous-gnu-extensions">;
-def fexceptions : Flag<"-fexceptions">,
- HelpText<"Enable support for exception handling">;
-def fobjc_exceptions : Flag<"-fobjc-exceptions">,
- HelpText<"Enable Objective-C exceptions">;
-def fcxx_exceptions : Flag<"-fcxx-exceptions">,
- HelpText<"Enable C++ exceptions">;
def fsjlj_exceptions : Flag<"-fsjlj-exceptions">,
HelpText<"Use SjLj style exceptions">;
-def ffast_math : Flag<"-ffast-math">,
- HelpText<"Enable the *frontend*'s 'fast-math' mode. This has no effect on "
- "optimizations, but provides a preprocessor macro __FAST_MATH__ the "
- "same as GCC's -ffast-math flag.">;
-def ffreestanding : Flag<"-ffreestanding">,
- HelpText<"Assert that the compilation takes place in a freestanding environment">;
-def fgnu_runtime : Flag<"-fgnu-runtime">,
- HelpText<"Generate output compatible with the standard GNU Objective-C runtime">;
def fhidden_weak_vtables : Flag<"-fhidden-weak-vtables">,
HelpText<"Generate weak vtables and RTTI with hidden visibility">;
-def std_EQ : Joined<"-std=">,
- HelpText<"Language standard to compile for">;
-def stdlib_EQ : Joined<"-stdlib=">,
- HelpText<"C++ standard library to use">;
-def fmath_errno : Flag<"-fmath-errno">,
- HelpText<"Require math functions to indicate errors by setting errno">;
-def fms_extensions : Flag<"-fms-extensions">,
- HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">;
-def fms_compatibility : Flag<"-fms-compatibility">,
- HelpText<"Enable Microsoft compatibility mode">;
-def fmsc_version : Joined<"-fmsc-version=">,
- HelpText<"Version of the Microsoft C/C++ compiler to report in _MSC_VER (0 = don't define it (default))">;
-def fborland_extensions : Flag<"-fborland-extensions">,
- HelpText<"Accept non-standard constructs supported by the Borland compiler">;
def main_file_name : Separate<"-main-file-name">,
HelpText<"Main file name to use for debug info">;
-def fno_elide_constructors : Flag<"-fno-elide-constructors">,
- HelpText<"Disable C++ copy constructor elision">;
-def fno_lax_vector_conversions : Flag<"-fno-lax-vector-conversions">,
- HelpText<"Disallow implicit conversions between vectors with a different number of elements or different element types">;
-def fno_operator_names : Flag<"-fno-operator-names">,
- HelpText<"Do not treat C++ operator name keywords as synonyms for operators">;
def fno_signed_char : Flag<"-fno-signed-char">,
HelpText<"Char is unsigned">;
-def fno_spell_checking : Flag<"-fno-spell-checking">,
- HelpText<"Disable spell-checking">;
-def fno_use_cxa_atexit : Flag<"-fno-use-cxa-atexit">,
- HelpText<"Don't use __cxa_atexit for calling destructors">;
def fconstant_string_class : Separate<"-fconstant-string-class">,
MetaVarName<"<class name>">,
HelpText<"Specify the class to use for constant Objective-C string objects.">;
-def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">,
- HelpText<"Enable creation of CodeFoundation-type constant strings">;
-def fobjc_arc : Flag<"-fobjc-arc">,
- HelpText<"Synthesize retain and release calls for Objective-C pointers">;
def fobjc_arc_cxxlib_EQ : Joined<"-fobjc-arc-cxxlib=">,
HelpText<"Objective-C++ Automatic Reference Counting standard library kind">;
-def fobjc_arc_exceptions : Flag<"-fobjc-arc-exceptions">,
- HelpText<"Use EH-safe code when synthesizing retains and releases in -fobjc-arc">;
def fobjc_runtime_has_arc : Flag<"-fobjc-runtime-has-arc">,
HelpText<"The target Objective-C runtime provides ARC entrypoints">;
def fobjc_runtime_has_weak : Flag<"-fobjc-runtime-has-weak">,
HelpText<"The target Objective-C runtime supports ARC weak operations">;
def fobjc_runtime_has_terminate : Flag<"-fobjc-runtime-has-terminate">,
HelpText<"The target Objective-C runtime provides an objc_terminate entrypoint">;
-def fobjc_gc : Flag<"-fobjc-gc">,
- HelpText<"Enable Objective-C garbage collection">;
-def fobjc_gc_only : Flag<"-fobjc-gc-only">,
- HelpText<"Use GC exclusively for Objective-C related memory management">;
-def fapple_kext : Flag<"-fapple-kext">,
- HelpText<"Use Apple's kernel extensions ABI">;
def fobjc_dispatch_method_EQ : Joined<"-fobjc-dispatch-method=">,
HelpText<"Objective-C dispatch method to use">;
def fobjc_default_synthesize_properties : Flag<"-fobjc-default-synthesize-properties">,
HelpText<"enable the default synthesis of Objective-C properties">;
-def print_ivar_layout : Flag<"-print-ivar-layout">,
- HelpText<"Enable Objective-C Ivar layout bitmap print trace">;
def fobjc_fragile_abi : Flag<"-fobjc-fragile-abi">,
HelpText<"Use Objective-C's fragile ABI">;
-def fno_objc_infer_related_result_type : Flag<
- "-fno-objc-infer-related-result-type">,
- HelpText<
- "do not infer Objective-C related result type based on method family">;
-def ftrapv : Flag<"-ftrapv">,
- HelpText<"Trap on integer overflow">;
-def ftrapv_handler : Separate<"-ftrapv-handler">,
- MetaVarName<"<function name>">,
- HelpText<"Specify the function to be called on overflow.">;
-def fwrapv : Flag<"-fwrapv">,
- HelpText<"Treat signed integer overflow as two's complement">;
def pic_level : Separate<"-pic-level">,
HelpText<"Value for __PIC__">;
def pie_level : Separate<"-pie-level">,
HelpText<"Value for __PIE__">;
-def pthread : Flag<"-pthread">,
- HelpText<"Support POSIX threads in generated code">;
-def fpack_struct : Separate<"-fpack-struct">,
- HelpText<"Specify the default maximum struct packing alignment">;
-def fpascal_strings : Flag<"-fpascal-strings">,
- HelpText<"Recognize and construct Pascal-style string literals">;
-def fno_rtti : Flag<"-fno-rtti">,
- HelpText<"Disable generation of rtti information">;
def fno_validate_pch : Flag<"-fno-validate-pch">,
HelpText<"Disable validation of precompiled headers">;
def dump_deserialized_pch_decls : Flag<"-dump-deserialized-decls">,
@@ -647,44 +408,24 @@
HelpText<"Emit error if a specific declaration is deserialized from PCH, for testing">;
def error_on_deserialized_pch_decl_EQ : Joined<"-error-on-deserialized-decl=">,
Alias<error_on_deserialized_pch_decl>;
-def fshort_wchar : Flag<"-fshort-wchar">,
- HelpText<"Force wchar_t to be a short unsigned int">;
-def fshort_enums : Flag<"-fshort-enums">,
- HelpText<"Allocate to an enum type only as many bytes as it needs for the declared range of possible values">;
def static_define : Flag<"-static-define">,
HelpText<"Should __STATIC__ be defined">;
def stack_protector : Separate<"-stack-protector">,
HelpText<"Enable stack protectors">;
def fvisibility : Separate<"-fvisibility">,
HelpText<"Default symbol visibility">;
-def fvisibility_inlines_hidden : Flag<"-fvisibility-inlines-hidden">,
- HelpText<"Give inline C++ member functions default visibility by default">;
def ftemplate_depth : Separate<"-ftemplate-depth">,
HelpText<"Maximum depth of recursive template instantiation">;
def fconstexpr_depth : Separate<"-fconstexpr-depth">,
HelpText<"Maximum depth of recursive constexpr function calls">;
-def Wlarge_by_value_copy : Separate<"-Wlarge-by-value-copy">,
- HelpText<"Warn if a function definition returns or accepts an object larger "
- "in bytes that a given value">;
-def Wlarge_by_value_copy_EQ : Joined<"-Wlarge-by-value-copy=">,
- Alias<Wlarge_by_value_copy>;
-def trigraphs : Flag<"-trigraphs">,
- HelpText<"Process trigraph sequences">;
-def fwritable_strings : Flag<"-fwritable-strings">,
- HelpText<"Store string literals as writable data">;
def fconst_strings : Flag<"-fconst-strings">,
HelpText<"Use a const qualified type for string literals in C and ObjC">;
def fno_const_strings : Flag<"-fno-const-strings">,
HelpText<"Don't use a const qualified type for string literals in C and ObjC">;
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">;
def ffake_address_space_map : Flag<"-ffake-address-space-map">,
HelpText<"Use a fake address space map; OpenCL testing purposes only">;
-def fdelayed_template_parsing : Flag<"-fdelayed-template-parsing">,
- HelpText<"Parse templated function definitions at the end of the "
- "translation unit ">;
def funknown_anytype : Flag<"-funknown-anytype">,
HelpText<"Enable parser support for the __unknown_anytype type; for testing purposes only">;
def fdebugger_support : Flag<"-fdebugger-support">,
@@ -697,8 +438,6 @@
HelpText<"Defines the __DEPRECATED macro">;
def fno_deprecated_macro : Flag<"-fno-deprecated-macro">,
HelpText<"Undefines the __DEPRECATED macro">;
-def fapple_pragma_pack : Flag<"-fapple-pragma-pack">,
- HelpText<"Enable Apple gcc-compatible #pragma pack handling">;
//===----------------------------------------------------------------------===//
// Header Search Options
@@ -706,48 +445,19 @@
def nostdsysteminc : Flag<"-nostdsysteminc">,
HelpText<"Disable standard system #include directories">;
-def nostdincxx : Flag<"-nostdinc++">,
- HelpText<"Disable standard #include directories for the C++ standard library">;
-def nobuiltininc : Flag<"-nobuiltininc">,
- HelpText<"Disable builtin #include directories">;
-def fmodule_cache_path : Separate<"-fmodule-cache-path">,
- MetaVarName<"<directory>">,
- HelpText<"Specify the module cache path">;
def fmodule_name : Joined<"-fmodule-name=">,
MetaVarName<"<name>">,
HelpText<"Specify the name of the module to build">;
def fdisable_module_hash : Flag<"-fdisable-module-hash">,
HelpText<"Disable the module hash">;
-def fmodules : Flag<"-fmodules">,
- HelpText<"Enable the 'modules' language feature">;
-
-def F : JoinedOrSeparate<"-F">, MetaVarName<"<directory>">,
- HelpText<"Add directory to framework include search path">;
-def I : JoinedOrSeparate<"-I">, MetaVarName<"<directory>">,
- HelpText<"Add directory to include search path">;
-def idirafter : JoinedOrSeparate<"-idirafter">, MetaVarName<"<directory>">,
- HelpText<"Add directory to AFTER include search path">;
-def index_header_map : Flag<"-index-header-map">,
- HelpText<"Make the next included directory (-I or -F) an indexer header map">;
-def iquote : JoinedOrSeparate<"-iquote">, MetaVarName<"<directory>">,
- HelpText<"Add directory to QUOTE include search path">;
def c_isystem : JoinedOrSeparate<"-c-isystem">, MetaVarName<"<directory>">,
HelpText<"Add directory to the C SYSTEM include search path">;
-def cxx_isystem : JoinedOrSeparate<"-cxx-isystem">, MetaVarName<"<directory>">,
- HelpText<"Add directory to the C++ SYSTEM include search path">;
def objc_isystem : JoinedOrSeparate<"-objc-isystem">,
MetaVarName<"<directory>">,
HelpText<"Add directory to the ObjC SYSTEM include search path">;
def objcxx_isystem : JoinedOrSeparate<"-objcxx-isystem">,
MetaVarName<"<directory>">,
HelpText<"Add directory to the ObjC++ SYSTEM include search path">;
-def iframework : JoinedOrSeparate<"-iframework">, MetaVarName<"<directory>">,
- HelpText<"Add directory to SYSTEM framework search path">;
-def isystem : JoinedOrSeparate<"-isystem">, MetaVarName<"<directory>">,
- HelpText<"Add directory to SYSTEM include search path">;
-def iwithsysroot : JoinedOrSeparate<"-iwithsysroot">,MetaVarName<"<directory>">,
- HelpText<"Add directory to SYSTEM include search path, "
- "absolute paths are relative to -isysroot">;
def internal_isystem : JoinedOrSeparate<"-internal-isystem">,
MetaVarName<"<directory>">,
HelpText<"Add directory to the internal system include search path; these "
@@ -759,29 +469,11 @@
"implicit extern \"C\" semantics; these are assumed to not be "
"user-provided and are used to model system and standard headers' "
"paths.">;
-def iprefix : JoinedOrSeparate<"-iprefix">, MetaVarName<"<prefix>">,
- HelpText<"Set the -iwithprefix/-iwithprefixbefore prefix">;
-def iwithprefix : JoinedOrSeparate<"-iwithprefix">, MetaVarName<"<dir>">,
- HelpText<"Set directory to SYSTEM include search path with prefix">;
-def iwithprefixbefore : JoinedOrSeparate<"-iwithprefixbefore">,
- MetaVarName<"<dir>">,
- HelpText<"Set directory to include search path with prefix">;
-def isysroot : JoinedOrSeparate<"-isysroot">, MetaVarName<"<dir>">,
- HelpText<"Set the system root directory (usually /)">;
-def v : Flag<"-v">, HelpText<"Enable verbose output">;
//===----------------------------------------------------------------------===//
// Preprocessor Options
//===----------------------------------------------------------------------===//
-def D : JoinedOrSeparate<"-D">, MetaVarName<"<macro>">,
- HelpText<"Predefine the specified macro">;
-def include_ : JoinedOrSeparate<"-include">, MetaVarName<"<file>">, EnumName<"include">,
- HelpText<"Include file before parsing">;
-def imacros : JoinedOrSeparate<"-imacros">, MetaVarName<"<file>">,
- HelpText<"Include macros from file before parsing">;
-def include_pch : Separate<"-include-pch">, MetaVarName<"<file>">,
- HelpText<"Include precompiled header file">;
def include_pth : Separate<"-include-pth">, MetaVarName<"<file>">,
HelpText<"Include file before parsing">;
def chain_include : Separate<"-chain-include">, MetaVarName<"<file>">,
@@ -791,29 +483,8 @@
"covering the first N bytes of the main file">;
def token_cache : Separate<"-token-cache">, MetaVarName<"<path>">,
HelpText<"Use specified token cache file">;
-def U : JoinedOrSeparate<"-U">, MetaVarName<"<macro>">,
- HelpText<"Undefine the specified macro">;
-def undef : Flag<"-undef">, MetaVarName<"<macro>">,
- HelpText<"undef all system defines">;
def detailed_preprocessing_record : Flag<"-detailed-preprocessing-record">,
HelpText<"include a detailed record of preprocessing actions">;
-def mqdsp6_compat : Flag<"-mqdsp6-compat">,
- HelpText<"Enable hexagon-qdsp6 backward compatibility">;
-
-//===----------------------------------------------------------------------===//
-// Preprocessed Output Options
-//===----------------------------------------------------------------------===//
-
-def P : Flag<"-P">,
- HelpText<"Disable linemarker output in -E mode">;
-def C : Flag<"-C">,
- HelpText<"Enable comment output in -E mode">;
-def CC : Flag<"-CC">,
- HelpText<"Enable comment output in -E mode, even from macro expansions">;
-def dM : Flag<"-dM">,
- HelpText<"Print macro definitions in -E mode instead of normal output">;
-def dD : Flag<"-dD">,
- HelpText<"Print macro definitions in -E mode in addition to normal output">;
//===----------------------------------------------------------------------===//
// OpenCL Options
@@ -840,3 +511,5 @@
def fcuda_is_device : Flag<"-fcuda-is-device">,
HelpText<"Generate code for CUDA device">;
+
+} // let Flags = [CC1Option]
Modified: cfe/branches/tooling/include/clang/Driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/CMakeLists.txt?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/CMakeLists.txt (original)
+++ cfe/branches/tooling/include/clang/Driver/CMakeLists.txt Tue May 8 03:47:31 2012
@@ -2,10 +2,6 @@
SOURCE Options.td
TARGET ClangDriverOptions)
-clang_tablegen(CC1Options.inc -gen-opt-parser-defs
- SOURCE CC1Options.td
- TARGET ClangCC1Options)
-
clang_tablegen(CC1AsOptions.inc -gen-opt-parser-defs
SOURCE CC1AsOptions.td
TARGET ClangCC1AsOptions)
Modified: cfe/branches/tooling/include/clang/Driver/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/Makefile?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/Makefile (original)
+++ cfe/branches/tooling/include/clang/Driver/Makefile Tue May 8 03:47:31 2012
@@ -1,5 +1,5 @@
CLANG_LEVEL := ../../..
-BUILT_SOURCES = Options.inc CC1Options.inc CC1AsOptions.inc
+BUILT_SOURCES = Options.inc CC1AsOptions.inc
TABLEGEN_INC_FILES_COMMON = 1
@@ -9,10 +9,6 @@
$(Echo) "Building Clang Driver Option tables with tblgen"
$(Verb) $(ClangTableGen) -gen-opt-parser-defs -o $(call SYSPATH, $@) $<
-$(ObjDir)/CC1Options.inc.tmp : CC1Options.td OptParser.td $(CLANG_TBLGEN) $(ObjDir)/.dir
- $(Echo) "Building Clang CC1 Option tables with tblgen"
- $(Verb) $(ClangTableGen) -gen-opt-parser-defs -o $(call SYSPATH, $@) $<
-
$(ObjDir)/CC1AsOptions.inc.tmp : CC1AsOptions.td OptParser.td $(CLANG_TBLGEN) $(ObjDir)/.dir
$(Echo) "Building Clang CC1 Assembler Option tables with tblgen"
$(Verb) $(ClangTableGen) -gen-opt-parser-defs -o $(call SYSPATH, $@) $<
Modified: cfe/branches/tooling/include/clang/Driver/OptParser.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/OptParser.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/OptParser.td (original)
+++ cfe/branches/tooling/include/clang/Driver/OptParser.td Tue May 8 03:47:31 2012
@@ -85,6 +85,9 @@
// NoForward - The option should not be implicitly forwarded to other tools.
def NoForward : OptionFlag;
+// CC1Option - This option should be accepted by clang -cc1.
+def CC1Option : OptionFlag;
+
// Define the option group class.
class OptionGroup<string name> {
@@ -134,5 +137,5 @@
// FIXME: Have generator validate that these appear in correct position (and
// aren't duplicated).
-def INPUT : Option<"<input>", KIND_INPUT>, Flags<[DriverOption]>;
+def INPUT : Option<"<input>", KIND_INPUT>, Flags<[DriverOption,CC1Option]>;
def UNKNOWN : Option<"<unknown>", KIND_UNKNOWN>;
Modified: cfe/branches/tooling/include/clang/Driver/OptTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/OptTable.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/OptTable.h (original)
+++ cfe/branches/tooling/include/clang/Driver/OptTable.h Tue May 8 03:47:31 2012
@@ -25,7 +25,8 @@
RenderAsInput = (1 << 5),
RenderJoined = (1 << 6),
RenderSeparate = (1 << 7),
- Unsupported = (1 << 8)
+ Unsupported = (1 << 8),
+ CC1Option = (1 << 9)
};
}
Modified: cfe/branches/tooling/include/clang/Driver/Option.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/Option.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/Option.h (original)
+++ cfe/branches/tooling/include/clang/Driver/Option.h Tue May 8 03:47:31 2012
@@ -91,6 +91,9 @@
/// This option should not be implicitly forwarded.
bool NoForward : 1;
+ /// CC1Option - This option should be accepted by clang -cc1.
+ bool CC1Option : 1;
+
protected:
Option(OptionClass Kind, OptSpecifier ID, const char *Name,
const OptionGroup *Group, const Option *Alias);
@@ -126,6 +129,9 @@
bool hasNoForward() const { return NoForward; }
void setNoForward(bool Value) { NoForward = Value; }
+ bool isCC1Option() const { return CC1Option; }
+ void setIsCC1Option(bool Value) { CC1Option = Value; }
+
bool hasForwardToGCC() const {
return !NoForward && !DriverOption && !LinkerInput;
}
Modified: cfe/branches/tooling/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/Options.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/Options.td (original)
+++ cfe/branches/tooling/include/clang/Driver/Options.td Tue May 8 03:47:31 2012
@@ -19,6 +19,7 @@
// Meta-group which defines
def CompileOnly_Group : OptionGroup<"<CompileOnly group>">;
+def Action_Group : OptionGroup<"<action group>">;
def I_Group : OptionGroup<"<I group>">, Group<CompileOnly_Group>;
def L_Group : OptionGroup<"<L group>">, Group<CompileOnly_Group>;
@@ -120,18 +121,19 @@
def ccc_arcmt_migrate : Separate<"-ccc-arcmt-migrate">, CCCDriverOpt,
HelpText<"Apply modifications and produces temporary files that conform to ARC">;
def arcmt_migrate_report_output : Separate<"-arcmt-migrate-report-output">,
- HelpText<"Output path for the plist report">;
+ HelpText<"Output path for the plist report">, Flags<[CC1Option]>;
def arcmt_migrate_emit_arc_errors : Flag<"-arcmt-migrate-emit-errors">,
- HelpText<"Emit ARC errors even if the migrator can fix them">;
+ HelpText<"Emit ARC errors even if the migrator can fix them">,
+ Flags<[CC1Option]>;
def _migrate : Flag<"--migrate">, Flags<[DriverOption]>,
HelpText<"Run the migrator">;
def ccc_objcmt_migrate : Separate<"-ccc-objcmt-migrate">, CCCDriverOpt,
HelpText<"Apply modifications and produces temporary files to migrate to "
"modern ObjC syntax">;
-def objcmt_migrate_literals : Flag<"-objcmt-migrate-literals">,
+def objcmt_migrate_literals : Flag<"-objcmt-migrate-literals">, Flags<[CC1Option]>,
HelpText<"Enable migration to modern ObjC literals">;
-def objcmt_migrate_subscripting : Flag<"-objcmt-migrate-subscripting">,
+def objcmt_migrate_subscripting : Flag<"-objcmt-migrate-subscripting">, Flags<[CC1Option]>,
HelpText<"Enable migration to modern ObjC subscripting">;
// Make sure all other -ccc- options are rejected.
@@ -146,66 +148,76 @@
def _DASH_DASH : Flag<"--">, Flags<[DriverOption]>;
def A : JoinedOrSeparate<"-A">;
def B : JoinedOrSeparate<"-B">;
-def CC : Flag<"-CC">;
-def C : Flag<"-C">;
-def D : JoinedOrSeparate<"-D">, Group<CompileOnly_Group>;
-def E : Flag<"-E">, Flags<[DriverOption]>,
+def CC : Flag<"-CC">, Flags<[CC1Option]>;
+def C : Flag<"-C">, Flags<[CC1Option]>;
+def D : JoinedOrSeparate<"-D">, Group<CompileOnly_Group>, Flags<[CC1Option]>;
+def E : Flag<"-E">, Flags<[DriverOption,CC1Option]>, Group<Action_Group>,
HelpText<"Only run the preprocessor">;
-def F : JoinedOrSeparate<"-F">, Flags<[RenderJoined]>;
+def F : JoinedOrSeparate<"-F">, Flags<[RenderJoined,CC1Option]>,
+ HelpText<"Add directory to framework include search path">;
def G : Separate<"-G">, Flags<[DriverOption]>;
-def H : Flag<"-H">;
+def H : Flag<"-H">, Flags<[CC1Option]>,
+ HelpText<"Show header includes and nesting depth">;
def I_ : Flag<"-I-">, Group<I_Group>;
-def I : JoinedOrSeparate<"-I">, Group<I_Group>;
+def I : JoinedOrSeparate<"-I">, Group<I_Group>, Flags<[CC1Option]>,
+ HelpText<"Add directory to include search path">;
def L : JoinedOrSeparate<"-L">, Flags<[RenderJoined]>;
def MD : Flag<"-MD">, Group<M_Group>;
def MF : JoinedOrSeparate<"-MF">, Group<M_Group>;
-def MG : Flag<"-MG">, Group<M_Group>;
+def MG : Flag<"-MG">, Group<M_Group>, Flags<[CC1Option]>,
+ HelpText<"Add missing headers to dependency list">;
def MMD : Flag<"-MMD">, Group<M_Group>;
def MM : Flag<"-MM">, Group<M_Group>;
-def MP : Flag<"-MP">, Group<M_Group>;
-def MQ : JoinedOrSeparate<"-MQ">, Group<M_Group>;
-def MT : JoinedOrSeparate<"-MT">, Group<M_Group>;
+def MP : Flag<"-MP">, Group<M_Group>, Flags<[CC1Option]>,
+ HelpText<"Create phony target for each dependency (other than main file)">;
+def MQ : JoinedOrSeparate<"-MQ">, Group<M_Group>, Flags<[CC1Option]>,
+ HelpText<"Specify target to quote for dependency">;
+def MT : JoinedOrSeparate<"-MT">, Group<M_Group>, Flags<[CC1Option]>,
+ HelpText<"Specify target for dependency">;
def Mach : Flag<"-Mach">;
def M : Flag<"-M">, Group<M_Group>;
-def O0 : Joined<"-O0">, Group<O_Group>;
-def O4 : Joined<"-O4">, Group<O_Group>;
+def O0 : Joined<"-O0">, Group<O_Group>, Flags<[CC1Option]>;
+def O4 : Joined<"-O4">, Group<O_Group>, Flags<[CC1Option]>;
def ObjCXX : Flag<"-ObjC++">, Flags<[DriverOption]>,
HelpText<"Treat source input files as Objective-C++ inputs">;
def ObjC : Flag<"-ObjC">, Flags<[DriverOption]>,
HelpText<"Treat source input files as Objective-C inputs">;
-def O : Joined<"-O">, Group<O_Group>;
-def P : Flag<"-P">;
+def O : Joined<"-O">, Group<O_Group>, Flags<[CC1Option]>;
+def P : Flag<"-P">, Flags<[CC1Option]>,
+ HelpText<"Disable linemarker output in -E mode">;
def Qn : Flag<"-Qn">;
def Qunused_arguments : Flag<"-Qunused-arguments">, Flags<[DriverOption]>,
HelpText<"Don't emit warning for unused driver arguments">;
def Q : Flag<"-Q">;
def R : Flag<"-R">;
-def S : Flag<"-S">, Flags<[DriverOption]>,
+def S : Flag<"-S">, Flags<[DriverOption,CC1Option]>, Group<Action_Group>,
HelpText<"Only run preprocess and compilation steps">;
def Tbss : JoinedOrSeparate<"-Tbss">, Group<T_Group>;
def Tdata : JoinedOrSeparate<"-Tdata">, Group<T_Group>;
def Ttext : JoinedOrSeparate<"-Ttext">, Group<T_Group>;
def T : JoinedOrSeparate<"-T">, Group<T_Group>;
-def U : JoinedOrSeparate<"-U">, Group<CompileOnly_Group>;
+def U : JoinedOrSeparate<"-U">, Group<CompileOnly_Group>, Flags<[CC1Option]>;
def V : JoinedOrSeparate<"-V">, Flags<[DriverOption, Unsupported]>;
def Wa_COMMA : CommaJoined<"-Wa,">,
HelpText<"Pass the comma separated arguments in <arg> to the assembler">,
MetaVarName<"<arg>">;
-def Wall : Flag<"-Wall">, Group<W_Group>;
-def Wdeprecated : Flag<"-Wdeprecated">, Group<W_Group>;
-def Wno_deprecated : Flag<"-Wno-deprecated">, Group<W_Group>;
-def Wextra : Flag<"-Wextra">, Group<W_Group>;
+def Wall : Flag<"-Wall">, Group<W_Group>, Flags<[CC1Option]>;
+def Wdeprecated : Flag<"-Wdeprecated">, Group<W_Group>, Flags<[CC1Option]>;
+def Wno_deprecated : Flag<"-Wno-deprecated">, Group<W_Group>, Flags<[CC1Option]>;
+def Wextra : Flag<"-Wextra">, Group<W_Group>, Flags<[CC1Option]>;
def Wl_COMMA : CommaJoined<"-Wl,">, Flags<[LinkerInput, RenderAsInput]>,
HelpText<"Pass the comma separated arguments in <arg> to the linker">,
MetaVarName<"<arg>">;
-def Wno_nonportable_cfstrings : Joined<"-Wno-nonportable-cfstrings">, Group<W_Group>;
-def Wnonportable_cfstrings : Joined<"-Wnonportable-cfstrings">, Group<W_Group>;
+def Wno_nonportable_cfstrings : Joined<"-Wno-nonportable-cfstrings">, Group<W_Group>,
+ Flags<[CC1Option]>;
+def Wnonportable_cfstrings : Joined<"-Wnonportable-cfstrings">, Group<W_Group>,
+ Flags<[CC1Option]>;
def Wp_COMMA : CommaJoined<"-Wp,">,
HelpText<"Pass the comma separated arguments in <arg> to the preprocessor">,
MetaVarName<"<arg>">;
-def Wwrite_strings : Flag<"-Wwrite-strings">, Group<W_Group>;
-def Wno_write_strings : Flag<"-Wno-write-strings">, Group<W_Group>;
-def W_Joined : Joined<"-W">, Group<W_Group>;
+def Wwrite_strings : Flag<"-Wwrite-strings">, Group<W_Group>, Flags<[CC1Option]>;
+def Wno_write_strings : Flag<"-Wno-write-strings">, Group<W_Group>, Flags<[CC1Option]>;
+def W_Joined : Joined<"-W">, Group<W_Group>, Flags<[CC1Option]>;
def Xanalyzer : Separate<"-Xanalyzer">,
HelpText<"Pass <arg> to the static analyzer">, MetaVarName<"<arg>">;
def Xarch__ : JoinedAndSeparate<"-Xarch_">, Flags<[DriverOption]>;
@@ -239,14 +251,21 @@
def coverage : Flag<"-coverage">;
def cpp_precomp : Flag<"-cpp-precomp">, Group<clang_ignored_f_Group>;
def current__version : JoinedOrSeparate<"-current_version">;
-def cxx_isystem : JoinedOrSeparate<"-cxx-isystem">, Group<clang_i_Group>;
+def cxx_isystem : JoinedOrSeparate<"-cxx-isystem">, Group<clang_i_Group>,
+ HelpText<"Add directory to the C++ SYSTEM include search path">, Flags<[CC1Option]>,
+ MetaVarName<"<directory>">;
def c : Flag<"-c">, Flags<[DriverOption]>,
HelpText<"Only run preprocess, compile, and assemble steps">;
def dA : Flag<"-dA">, Group<d_Group>;
-def dD : Flag<"-dD">, Group<d_Group>;
-def dM : Flag<"-dM">, Group<d_Group>;
+def dD : Flag<"-dD">, Group<d_Group>, Flags<[CC1Option]>,
+ HelpText<"Print macro definitions in -E mode in addition to normal output">;
+def dM : Flag<"-dM">, Group<d_Group>, Flags<[CC1Option]>,
+ HelpText<"Print macro definitions in -E mode instead of normal output">;
def dead__strip : Flag<"-dead_strip">;
-def dependency_file : Separate<"-dependency-file">;
+def dependency_file : Separate<"-dependency-file">, Flags<[CC1Option]>,
+ HelpText<"Filename (or -) to write dependency output to">;
+def dependency_dot : Separate<"-dependency-dot">, Flags<[CC1Option]>,
+ HelpText<"Filename to write DOT-formatted header dependencies to">;
def dumpmachine : Flag<"-dumpmachine">;
def dumpspecs : Flag<"-dumpspecs">, Flags<[Unsupported]>;
def dumpversion : Flag<"-dumpversion">;
@@ -259,7 +278,7 @@
def d_Joined : Joined<"-d">, Group<d_Group>;
def emit_ast : Flag<"-emit-ast">,
HelpText<"Emit Clang AST files for source inputs">;
-def emit_llvm : Flag<"-emit-llvm">,
+def emit_llvm : Flag<"-emit-llvm">, Flags<[CC1Option]>, Group<Action_Group>,
HelpText<"Use the LLVM representation for assembler and object files">;
def exported__symbols__list : Separate<"-exported_symbols_list">;
def e : JoinedOrSeparate<"-e">;
@@ -269,13 +288,18 @@
def fno_PIE : Flag<"-fno-PIE">, Group<f_Group>;
def faccess_control : Flag<"-faccess-control">, Group<f_Group>;
def fallow_unsupported : Flag<"-fallow-unsupported">, Group<f_Group>;
-def faltivec : Flag<"-faltivec">, Group<f_Group>;
-def fapple_kext : Flag<"-fapple-kext">, Group<f_Group>;
-def fapple_pragma_pack : Flag<"-fapple-pragma-pack">, Group<f_Group>;
-def faddress_sanitizer : Flag<"-faddress-sanitizer">, Group<f_Group>;
-def fno_address_sanitizer : Flag<"-fno-address-sanitizer">, Group<f_Group>;
-def fthread_sanitizer : Flag<"-fthread-sanitizer">, Group<f_Group>;
-def fno_thread_sanitizer : Flag<"-fno-thread-sanitizer">, Group<f_Group>;
+def faltivec : Flag<"-faltivec">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable AltiVec vector initializer syntax">;
+def fapple_kext : Flag<"-fapple-kext">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Use Apple's kernel extensions ABI">;
+def fapple_pragma_pack : Flag<"-fapple-pragma-pack">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable Apple gcc-compatible #pragma pack handling">;
+def faddress_sanitizer : Flag<"-faddress-sanitizer">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable AddressSanitizer instrumentation (memory error detection)">;
+def fno_address_sanitizer : Flag<"-fno-address-sanitizer">, Group<f_Group>, Flags<[CC1Option]>;
+def fthread_sanitizer : Flag<"-fthread-sanitizer">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable ThreadSanitizer instrumentation (race detection)">;
+def fno_thread_sanitizer : Flag<"-fno-thread-sanitizer">, Group<f_Group>, Flags<[CC1Option]>;
def fasm : Flag<"-fasm">, Group<f_Group>;
def fasm_blocks : Flag<"-fasm-blocks">, Group<f_Group>;
@@ -286,17 +310,20 @@
def fastf : Flag<"-fastf">, Group<f_Group>;
def fast : Flag<"-fast">, Group<f_Group>;
def fasynchronous_unwind_tables : Flag<"-fasynchronous-unwind-tables">, Group<f_Group>;
-def fblocks : Flag<"-fblocks">, Group<f_Group>;
+def fblocks : Flag<"-fblocks">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable the 'blocks' language feature">;
def fbootclasspath_EQ : Joined<"-fbootclasspath=">, Group<f_Group>;
-def fborland_extensions : Flag<"-fborland-extensions">, Group<f_Group>;
+def fborland_extensions : Flag<"-fborland-extensions">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Accept non-standard constructs supported by the Borland compiler">;
def fbuiltin_strcat : Flag<"-fbuiltin-strcat">, Group<f_Group>;
def fbuiltin_strcpy : Flag<"-fbuiltin-strcpy">, Group<f_Group>;
def fbuiltin : Flag<"-fbuiltin">, Group<f_Group>;
def fcaret_diagnostics : Flag<"-fcaret-diagnostics">, Group<f_Group>;
-def fcatch_undefined_behavior : Flag<"-fcatch-undefined-behavior">,
- Group<f_Group>, HelpText<"Generate runtime checks for undefined behavior.">;
+def fcatch_undefined_behavior : Flag<"-fcatch-undefined-behavior">, Flags<[CC1Option]>,
+ Group<f_Group>, HelpText<"Generate runtime checks for undefined behavior.">;
def fclasspath_EQ : Joined<"-fclasspath=">, Group<f_Group>;
-def fcolor_diagnostics : Flag<"-fcolor-diagnostics">, Group<f_Group>;
+def fcolor_diagnostics : Flag<"-fcolor-diagnostics">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Use colors in diagnostics">;
def fcommon : Flag<"-fcommon">, Group<f_Group>;
def fcompile_resource_EQ : Joined<"-fcompile-resource=">, Group<f_Group>;
def fconstant_cfstrings : Flag<"-fconstant-cfstrings">, Group<f_Group>;
@@ -306,32 +333,47 @@
Group<f_Group>;
def fno_crash_diagnostics : Flag<"-fno-crash-diagnostics">, Group<f_clang_Group>, Flags<[NoArgumentUnused]>;
def fcreate_profile : Flag<"-fcreate-profile">, Group<f_Group>;
-def fcxx_exceptions: Flag<"-fcxx-exceptions">, Group<f_Group>;
+def fcxx_exceptions: Flag<"-fcxx-exceptions">, Group<f_Group>,
+ HelpText<"Enable C++ exceptions">, Flags<[CC1Option]>;
def fcxx_modules : Flag <"-fcxx-modules">, Group<f_Group>, Flags<[NoForward]>;
def fdebug_pass_arguments : Flag<"-fdebug-pass-arguments">, Group<f_Group>;
def fdebug_pass_structure : Flag<"-fdebug-pass-structure">, Group<f_Group>;
def fdiagnostics_fixit_info : Flag<"-fdiagnostics-fixit-info">, Group<f_clang_Group>;
-def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-range-info">, Group<f_clang_Group>;
-def fdiagnostics_parseable_fixits : Flag<"-fdiagnostics-parseable-fixits">, Group<f_clang_Group>;
-def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">, Group<f_Group>;
-def fdiagnostics_show_note_include_stack : Flag<"-fdiagnostics-show-note-include-stack">, Group<f_Group>;
+def fdiagnostics_parseable_fixits : Flag<"-fdiagnostics-parseable-fixits">, Group<f_clang_Group>,
+ Flags<[CC1Option]>, HelpText<"Print fix-its in machine parseable form">;
+def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-range-info">,
+ Group<f_clang_Group>, Flags<[CC1Option]>,
+ HelpText<"Print source range spans in numeric form">;
+def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Print option name with mappable diagnostics">;
+def fdiagnostics_show_name : Flag<"-fdiagnostics-show-name">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Print diagnostic name">;
+def fdiagnostics_show_note_include_stack : Flag<"-fdiagnostics-show-note-include-stack">,
+ Group<f_Group>, Flags<[CC1Option]>, HelpText<"Display include stacks for diagnostic notes">;
def fdiagnostics_format_EQ : Joined<"-fdiagnostics-format=">, Group<f_clang_Group>;
def fdiagnostics_show_category_EQ : Joined<"-fdiagnostics-show-category=">, Group<f_clang_Group>;
-def fdollars_in_identifiers : Flag<"-fdollars-in-identifiers">, Group<f_Group>;
+def fdollars_in_identifiers : Flag<"-fdollars-in-identifiers">, Group<f_Group>,
+ HelpText<"Allow '$' in identifiers">, Flags<[CC1Option]>;
def fdwarf2_cfi_asm : Flag<"-fdwarf2-cfi-asm">, Group<f_Group>;
-def fno_dwarf2_cfi_asm : Flag<"-fno-dwarf2-cfi-asm">, Group<f_Group>;
+def fno_dwarf2_cfi_asm : Flag<"-fno-dwarf2-cfi-asm">, Group<f_Group>, Flags<[CC1Option]>;
def fdwarf_directory_asm : Flag<"-fdwarf-directory-asm">, Group<f_Group>;
-def fno_dwarf_directory_asm : Flag<"-fno-dwarf-directory-asm">, Group<f_Group>;
+def fno_dwarf_directory_asm : Flag<"-fno-dwarf-directory-asm">, Group<f_Group>, Flags<[CC1Option]>;
def felide_constructors : Flag<"-felide-constructors">, Group<f_Group>;
def feliminate_unused_debug_symbols : Flag<"-feliminate-unused-debug-symbols">, Group<f_Group>;
-def femit_all_decls : Flag<"-femit-all-decls">, Group<f_Group>;
+def femit_all_decls : Flag<"-femit-all-decls">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Emit all declarations, even if unused">;
def fencoding_EQ : Joined<"-fencoding=">, Group<f_Group>;
def ferror_limit_EQ : Joined<"-ferror-limit=">, Group<f_Group>;
-def fexceptions : Flag<"-fexceptions">, Group<f_Group>;
+def fexceptions : Flag<"-fexceptions">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable support for exception handling">;
def fextdirs_EQ : Joined<"-fextdirs=">, Group<f_Group>;
def fhosted : Flag<"-fhosted">, Group<f_Group>;
-def ffast_math : Flag<"-ffast-math">, Group<f_Group>;
-def fmath_errno : Flag<"-fmath-errno">, Group<f_Group>;
+def ffast_math : Flag<"-ffast-math">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable the *frontend*'s 'fast-math' mode. This has no effect on "
+ "optimizations, but provides a preprocessor macro __FAST_MATH__ the "
+ "same as GCC's -ffast-math flag.">;
+def fmath_errno : Flag<"-fmath-errno">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Require math functions to indicate errors by setting errno">;
def fno_math_errno : Flag<"-fno-math-errno">, Group<f_Group>;
def fsignaling_math : Flag<"-fsignaling-math">, Group<f_Group>;
def fno_signaling_math : Flag<"-fno-signaling-math">, Group<f_Group>;
@@ -360,21 +402,26 @@
def ffor_scope : Flag<"-ffor-scope">, Group<f_Group>;
def fno_for_scope : Flag<"-fno-for-scope">, Group<f_Group>;
-def ffreestanding : Flag<"-ffreestanding">, Group<f_Group>;
-def fgnu_keywords : Flag<"-fgnu-keywords">, Group<f_Group>;
-def fgnu89_inline : Flag<"-fgnu89-inline">, Group<f_Group>;
+def ffreestanding : Flag<"-ffreestanding">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Assert that the compilation takes place in a freestanding environment">;
+def fgnu_keywords : Flag<"-fgnu-keywords">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Allow GNU-extension keywords regardless of language standard">;
+def fgnu89_inline : Flag<"-fgnu89-inline">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Use the gnu89 inline semantics">;
def fno_gnu89_inline : Flag<"-fno-gnu89-inline">, Group<f_Group>;
-def fgnu_runtime : Flag<"-fgnu-runtime">, Group<f_Group>;
-def fheinous_gnu_extensions : Flag<"-fheinous-gnu-extensions">;
+def fgnu_runtime : Flag<"-fgnu-runtime">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Generate output compatible with the standard GNU Objective-C runtime">;
+def fheinous_gnu_extensions : Flag<"-fheinous-gnu-extensions">, Flags<[CC1Option]>;
def filelist : Separate<"-filelist">, Flags<[LinkerInput]>;
def findirect_virtual_calls : Flag<"-findirect-virtual-calls">, Alias<fapple_kext>;
def finline_functions : Flag<"-finline-functions">, Group<clang_ignored_f_Group>;
def finline : Flag<"-finline">, Group<clang_ignored_f_Group>;
-def finstrument_functions : Flag<"-finstrument-functions">, Group<f_Group>;
+def finstrument_functions : Flag<"-finstrument-functions">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Generate calls to instrument function entry and exit">;
def fkeep_inline_functions : Flag<"-fkeep-inline-functions">, Group<clang_ignored_f_Group>;
def flat__namespace : Flag<"-flat_namespace">;
def flax_vector_conversions : Flag<"-flax-vector-conversions">, Group<f_Group>;
-def flimit_debug_info : Flag<"-flimit-debug-info">, Group<f_Group>,
+def flimit_debug_info : Flag<"-flimit-debug-info">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Limit debug information produced to reduce size of debug binary">;
def flimited_precision_EQ : Joined<"-flimited-precision=">, Group<f_Group>;
def flto : Flag<"-flto">, Group<f_Group>;
@@ -383,49 +430,71 @@
Group<f_Group>;
def fmerge_all_constants : Flag<"-fmerge-all-constants">, Group<f_Group>;
def fmessage_length_EQ : Joined<"-fmessage-length=">, Group<f_Group>;
-def fms_extensions : Flag<"-fms-extensions">, Group<f_Group>;
-def fms_compatibility : Flag<"-fms-compatibility">, Group<f_Group>;
-def fmsc_version : Joined<"-fmsc-version=">, Group<f_Group>;
-def fdelayed_template_parsing : Flag<"-fdelayed-template-parsing">, Group<f_Group>;
+def fms_extensions : Flag<"-fms-extensions">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">;
+def fms_compatibility : Flag<"-fms-compatibility">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable Microsoft compatibility mode">;
+def fmsc_version : Joined<"-fmsc-version=">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Version of the Microsoft C/C++ compiler to report in _MSC_VER (0 = don't define it (default))">;
+def fdelayed_template_parsing : Flag<"-fdelayed-template-parsing">, Group<f_Group>,
+ HelpText<"Parse templated function definitions at the end of the "
+ "translation unit ">, Flags<[CC1Option]>;
def fmodule_cache_path : Separate<"-fmodule-cache-path">, Group<i_Group>,
- Flags<[NoForward]>;
-def fmodules : Flag <"-fmodules">, Group<f_Group>, Flags<[NoForward]>;
+ Flags<[NoForward,CC1Option]>, MetaVarName<"<directory>">,
+ HelpText<"Specify the module cache path">;
+def fmodules : Flag <"-fmodules">, Group<f_Group>, Flags<[NoForward,CC1Option]>,
+ HelpText<"Enable the 'modules' language feature">;
def fmudflapth : Flag<"-fmudflapth">, Group<f_Group>;
def fmudflap : Flag<"-fmudflap">, Group<f_Group>;
def fnested_functions : Flag<"-fnested-functions">, Group<f_Group>;
def fnext_runtime : Flag<"-fnext-runtime">, Group<f_Group>;
-def fno_access_control : Flag<"-fno-access-control">, Group<f_Group>;
+def fno_access_control : Flag<"-fno-access-control">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Disable C++ access control">;
def fno_apple_pragma_pack : Flag<"-fno-apple-pragma-pack">, Group<f_Group>;
def fno_asm : Flag<"-fno-asm">, Group<f_Group>;
def fno_asynchronous_unwind_tables : Flag<"-fno-asynchronous-unwind-tables">, Group<f_Group>;
-def fno_assume_sane_operator_new : Flag<"-fno-assume-sane-operator-new">, Group<f_Group>;
+def fno_assume_sane_operator_new : Flag<"-fno-assume-sane-operator-new">, Group<f_Group>,
+ HelpText<"Don't assume that C++'s global operator new can't alias any pointer">,
+ Flags<[CC1Option]>;
def fno_blocks : Flag<"-fno-blocks">, Group<f_Group>;
def fno_borland_extensions : Flag<"-fno-borland-extensions">, Group<f_Group>;
def fno_builtin_strcat : Flag<"-fno-builtin-strcat">, Group<f_Group>;
def fno_builtin_strcpy : Flag<"-fno-builtin-strcpy">, Group<f_Group>;
-def fno_builtin : Flag<"-fno-builtin">, Group<f_Group>;
-def fno_caret_diagnostics : Flag<"-fno-caret-diagnostics">, Group<f_Group>;
+def fno_builtin : Flag<"-fno-builtin">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Disable implicit builtin knowledge of functions">;
+def fno_caret_diagnostics : Flag<"-fno-caret-diagnostics">, Group<f_Group>,
+ Flags<[CC1Option]>;
def fno_color_diagnostics : Flag<"-fno-color-diagnostics">, Group<f_Group>;
-def fno_common : Flag<"-fno-common">, Group<f_Group>;
-def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">, Group<f_Group>;
+def fno_common : Flag<"-fno-common">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Compile common globals like normal definitions">;
+def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">, Group<f_Group>,
+ Flags<[CC1Option]>,
+ HelpText<"Disable creation of CodeFoundation-type constant strings">;
def fno_cxx_exceptions: Flag<"-fno-cxx-exceptions">, Group<f_Group>;
def fno_cxx_modules : Flag <"-fno-cxx-modules">, Group<f_Group>, Flags<[NoForward]>;
-def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">, Group<f_Group>;
+def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Do not include fixit information in diagnostics">;
+def fno_diagnostics_show_name : Flag<"-fno-diagnostics-show-name">, Group<f_Group>;
def fno_diagnostics_show_option : Flag<"-fno-diagnostics-show-option">, Group<f_Group>;
-def fno_diagnostics_show_note_include_stack : Flag<"-fno-diagnostics-show-note-include-stack">, Group<f_Group>;
-def fno_dollars_in_identifiers : Flag<"-fno-dollars-in-identifiers">, Group<f_Group>;
-def fno_elide_constructors : Flag<"-fno-elide-constructors">, Group<f_Group>;
+def fno_diagnostics_show_note_include_stack : Flag<"-fno-diagnostics-show-note-include-stack">,
+ Flags<[CC1Option]>, Group<f_Group>, HelpText<"Display include stacks for diagnostic notes">;
+def fno_dollars_in_identifiers : Flag<"-fno-dollars-in-identifiers">, Group<f_Group>,
+ HelpText<"Disallow '$' in identifiers">, Flags<[CC1Option]>;
+def fno_elide_constructors : Flag<"-fno-elide-constructors">, Group<f_Group>,
+ HelpText<"Disable C++ copy constructor elision">, Flags<[CC1Option]>;
def fno_eliminate_unused_debug_symbols : Flag<"-fno-eliminate-unused-debug-symbols">, Group<f_Group>;
def fno_exceptions : Flag<"-fno-exceptions">, Group<f_Group>;
-def fno_gnu_keywords : Flag<"-fno-gnu-keywords">, Group<f_Group>;
-def fno_inline_functions : Flag<"-fno-inline-functions">, Group<f_Group>;
-def fno_inline : Flag<"-fno-inline">, Group<f_Group>;
+def fno_gnu_keywords : Flag<"-fno-gnu-keywords">, Group<f_Group>, Flags<[CC1Option]>;
+def fno_inline_functions : Flag<"-fno-inline-functions">, Group<f_clang_Group>, Flags<[CC1Option]>;
+def fno_inline : Flag<"-fno-inline">, Group<f_clang_Group>, Flags<[CC1Option]>;
def fno_keep_inline_functions : Flag<"-fno-keep-inline-functions">, Group<clang_ignored_f_Group>;
-def fno_lax_vector_conversions : Flag<"-fno-lax-vector-conversions">, Group<f_Group>;
-def fno_limit_debug_info : Flag<"-fno-limit-debug-info">, Group<f_Group>,
+def fno_lax_vector_conversions : Flag<"-fno-lax-vector-conversions">, Group<f_Group>,
+ HelpText<"Disallow implicit conversions between vectors with a different number of elements or different element types">, Flags<[CC1Option]>;
+def fno_limit_debug_info : Flag<"-fno-limit-debug-info">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Do not limit debug information produced to reduce size of debug binary">;
-def fno_merge_all_constants : Flag<"-fno-merge-all-constants">, Group<f_Group>;
+def fno_merge_all_constants : Flag<"-fno-merge-all-constants">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Disallow merging of constants.">;
def fno_modules : Flag <"-fno-modules">, Group<f_Group>, Flags<[NoForward]>;
def fno_ms_extensions : Flag<"-fno-ms-extensions">, Group<f_Group>;
def fno_ms_compatibility : Flag<"-fno-ms-compatibility">, Group<f_Group>;
@@ -433,41 +502,57 @@
def fno_objc_exceptions: Flag<"-fno-objc-exceptions">, Group<f_Group>;
def fno_objc_legacy_dispatch : Flag<"-fno-objc-legacy-dispatch">, Group<f_Group>;
def fno_omit_frame_pointer : Flag<"-fno-omit-frame-pointer">, Group<f_Group>;
-def fno_operator_names : Flag<"-fno-operator-names">, Group<f_Group>;
+def fno_operator_names : Flag<"-fno-operator-names">, Group<f_Group>,
+ HelpText<"Do not treat C++ operator name keywords as synonyms for operators">,
+ Flags<[CC1Option]>;
def fno_pascal_strings : Flag<"-fno-pascal-strings">, Group<f_Group>;
-def fno_rtti : Flag<"-fno-rtti">, Group<f_Group>;
+def fno_rtti : Flag<"-fno-rtti">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Disable generation of rtti information">;
def fno_short_enums : Flag<"-fno-short-enums">, Group<f_Group>;
-def fno_show_column : Flag<"-fno-show-column">, Group<f_Group>;
-def fno_show_source_location : Flag<"-fno-show-source-location">, Group<f_Group>;
-def fno_spell_checking : Flag<"-fno-spell-checking">, Group<f_Group>;
+def fno_show_column : Flag<"-fno-show-column">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Do not include column number on diagnostics">;
+def fno_show_source_location : Flag<"-fno-show-source-location">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Do not include source location information with diagnostics">;
+def fno_spell_checking : Flag<"-fno-spell-checking">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Disable spell-checking">;
def fno_stack_protector : Flag<"-fno-stack-protector">, Group<f_Group>;
def fno_strict_aliasing : Flag<"-fno-strict-aliasing">, Group<f_Group>;
def fno_strict_enums : Flag<"-fno-strict-enums">, Group<f_Group>;
def fno_strict_overflow : Flag<"-fno-strict-overflow">, Group<f_Group>;
-def fno_threadsafe_statics : Flag<"-fno-threadsafe-statics">, Group<f_Group>;
-def fno_use_cxa_atexit : Flag<"-fno-use-cxa-atexit">, Group<f_Group>;
+def fno_threadsafe_statics : Flag<"-fno-threadsafe-statics">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Do not emit code to make initialization of local statics thread safe">;
+def fno_use_cxa_atexit : Flag<"-fno-use-cxa-atexit">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Don't use __cxa_atexit for calling destructors">;
def fno_unit_at_a_time : Flag<"-fno-unit-at-a-time">, Group<f_Group>;
def fno_unwind_tables : Flag<"-fno-unwind-tables">, Group<f_Group>;
def fno_verbose_asm : Flag<"-fno-verbose-asm">, Group<f_Group>;
def fno_working_directory : Flag<"-fno-working-directory">, Group<f_Group>;
def fno_wrapv : Flag<"-fno-wrapv">, Group<f_Group>;
def fno_zero_initialized_in_bss : Flag<"-fno-zero-initialized-in-bss">, Group<f_Group>;
-def fobjc_arc : Flag<"-fobjc-arc">, Group<f_Group>;
+def fobjc_arc : Flag<"-fobjc-arc">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Synthesize retain and release calls for Objective-C pointers">;
def fno_objc_arc : Flag<"-fno-objc-arc">, Group<f_Group>;
-def fobjc_arc_exceptions : Flag<"-fobjc-arc-exceptions">, Group<f_Group>;
+def fobjc_arc_exceptions : Flag<"-fobjc-arc-exceptions">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Use EH-safe code when synthesizing retains and releases in -fobjc-arc">;
def fno_objc_arc_exceptions : Flag<"-fno-objc-arc-exceptions">, Group<f_Group>;
def fobjc_atdefs : Flag<"-fobjc-atdefs">, Group<clang_ignored_f_Group>;
def fobjc_call_cxx_cdtors : Flag<"-fobjc-call-cxx-cdtors">, Group<clang_ignored_f_Group>;
-def fobjc_exceptions: Flag<"-fobjc-exceptions">, Group<f_Group>;
+def fobjc_exceptions: Flag<"-fobjc-exceptions">, Group<f_Group>,
+ HelpText<"Enable Objective-C exceptions">, Flags<[CC1Option]>;
-def fobjc_gc_only : Flag<"-fobjc-gc-only">, Group<f_Group>;
-def fobjc_gc : Flag<"-fobjc-gc">, Group<f_Group>;
+def fobjc_gc_only : Flag<"-fobjc-gc-only">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Use GC exclusively for Objective-C related memory management">;
+def fobjc_gc : Flag<"-fobjc-gc">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable Objective-C garbage collection">;
def fobjc_legacy_dispatch : Flag<"-fobjc-legacy-dispatch">, Group<f_Group>;
def fobjc_new_property : Flag<"-fobjc-new-property">, Group<clang_ignored_f_Group>;
def fobjc_infer_related_result_type : Flag<"-fobjc-infer-related-result-type">,
Group<f_Group>;
def fno_objc_infer_related_result_type : Flag<
- "-fno-objc-infer-related-result-type">, Group<f_Group>;
+ "-fno-objc-infer-related-result-type">, Group<f_Group>,
+ HelpText<
+ "do not infer Objective-C related result type based on method family">,
+ Flags<[CC1Option]>;
def fobjc_link_runtime: Flag<"-fobjc-link-runtime">, Group<f_Group>;
// Objective-C ABI options.
@@ -488,8 +573,10 @@
def foutput_class_dir_EQ : Joined<"-foutput-class-dir=">, Group<f_Group>;
def fpack_struct : Flag<"-fpack-struct">, Group<f_Group>;
def fno_pack_struct : Flag<"-fno-pack-struct">, Group<f_Group>;
-def fpack_struct_EQ : Joined<"-fpack-struct=">, Group<f_Group>;
-def fpascal_strings : Flag<"-fpascal-strings">, Group<f_Group>;
+def fpack_struct_EQ : Joined<"-fpack-struct=">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Specify the default maximum struct packing alignment">;
+def fpascal_strings : Flag<"-fpascal-strings">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Recognize and construct Pascal-style string literals">;
def fpch_preprocess : Flag<"-fpch-preprocess">, Group<f_Group>;
def fpic : Flag<"-fpic">, Group<f_Group>;
def fno_pic : Flag<"-fno-pic">, Group<f_Group>;
@@ -501,11 +588,15 @@
def frandom_seed_EQ : Joined<"-frandom-seed=">, Group<clang_ignored_f_Group>;
def frtti : Flag<"-frtti">, Group<f_Group>;
def fsched_interblock : Flag<"-fsched-interblock">, Group<clang_ignored_f_Group>;
-def fshort_enums : Flag<"-fshort-enums">, Group<f_Group>;
+def fshort_enums : Flag<"-fshort-enums">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Allocate to an enum type only as many bytes as it needs for the declared range of possible values">;
def freorder_blocks : Flag<"-freorder-blocks">, Group<clang_ignored_f_Group>;
-def fshort_wchar : Flag<"-fshort-wchar">, Group<f_Group>;
-def fshow_overloads_EQ : Joined<"-fshow-overloads=">, Group<f_Group>;
-def fshow_column : Flag<"-fshow-column">, Group<f_Group>;
+def fshort_wchar : Flag<"-fshort-wchar">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Force wchar_t to be a short unsigned int">;
+def fshow_overloads_EQ : Joined<"-fshow-overloads=">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Which overload candidates to show when overload resolution fails: "
+ "best|all; defaults to all">;
+def fshow_column : Flag<"-fshow-column">, Group<f_Group>, Flags<[CC1Option]>;
def fshow_source_location : Flag<"-fshow-source-location">, Group<f_Group>;
def fspell_checking : Flag<"-fspell-checking">, Group<f_Group>;
def fsigned_bitfields : Flag<"-fsigned-bitfields">, Group<f_Group>;
@@ -513,17 +604,21 @@
def fstack_protector_all : Flag<"-fstack-protector-all">, Group<f_Group>;
def fstack_protector : Flag<"-fstack-protector">, Group<f_Group>;
def fstrict_aliasing : Flag<"-fstrict-aliasing">, Group<f_Group>;
-def fstrict_enums : Flag<"-fstrict-enums">, Group<f_Group>;
+def fstrict_enums : Flag<"-fstrict-enums">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Enable optimizations based on the strict definition of an enum's "
+ "value range.">;
def fstrict_overflow : Flag<"-fstrict-overflow">, Group<f_Group>;
-def fsyntax_only : Flag<"-fsyntax-only">, Flags<[DriverOption]>;
+def fsyntax_only : Flag<"-fsyntax-only">, Flags<[DriverOption,CC1Option]>, Group<Action_Group>;
def ftabstop_EQ : Joined<"-ftabstop=">, Group<f_Group>;
def ftemplate_depth_EQ : Joined<"-ftemplate-depth=">, Group<f_Group>;
def ftemplate_depth_ : Joined<"-ftemplate-depth-">, Group<f_Group>;
def ftemplate_backtrace_limit_EQ : Joined<"-ftemplate-backtrace-limit=">,
Group<f_Group>;
def ftest_coverage : Flag<"-ftest-coverage">, Group<f_Group>;
-def Wlarge_by_value_copy_def : Flag<"-Wlarge-by-value-copy">;
-def Wlarge_by_value_copy_EQ : Joined<"-Wlarge-by-value-copy=">;
+def Wlarge_by_value_copy_def : Flag<"-Wlarge-by-value-copy">,
+ HelpText<"Warn if a function definition returns or accepts an object larger "
+ "in bytes that a given value">;
+def Wlarge_by_value_copy_EQ : Joined<"-Wlarge-by-value-copy=">, Flags<[CC1Option]>;
// Just silence warnings about -Wlarger-than, -Wframe-larger-than for now.
def Wlarger_than : Separate<"-Wlarger-than">, Group<clang_ignored_f_Group>;
@@ -534,25 +629,36 @@
def fterminated_vtables : Flag<"-fterminated-vtables">, Alias<fapple_kext>;
def fthreadsafe_statics : Flag<"-fthreadsafe-statics">, Group<f_Group>;
-def ftime_report : Flag<"-ftime-report">, Group<f_Group>;
-def ftrapv : Flag<"-ftrapv">, Group<f_Group>;
-def ftrapv_handler_EQ : Joined<"-ftrapv-handler=">, Group<f_Group>;
-def ftrap_function_EQ : Joined<"-ftrap-function=">, Group<f_Group>,
+def ftime_report : Flag<"-ftime-report">, Group<f_Group>, Flags<[CC1Option]>;
+def ftrapv : Flag<"-ftrapv">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Trap on integer overflow">;
+def ftrapv_handler_EQ : Joined<"-ftrapv-handler=">, Group<f_Group>,
+ MetaVarName<"<function name>">,
+ HelpText<"Specify the function to be called on overflow.">;
+def ftrapv_handler : Separate<"-ftrapv-handler">, Group<f_Group>, Flags<[CC1Option]>;
+def ftrap_function_EQ : Joined<"-ftrap-function=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Issue call to specified function rather than a trap instruction">;
def funit_at_a_time : Flag<"-funit-at-a-time">, Group<f_Group>;
-def funroll_loops : Flag<"-funroll-loops">, Group<f_Group>;
+def funroll_loops : Flag<"-funroll-loops">, Group<f_Group>,
+ HelpText<"Turn on loop unroller">, Flags<[CC1Option]>;
def funsigned_bitfields : Flag<"-funsigned-bitfields">, Group<f_Group>;
def funsigned_char : Flag<"-funsigned-char">, Group<f_Group>;
def funwind_tables : Flag<"-funwind-tables">, Group<f_Group>;
def fuse_cxa_atexit : Flag<"-fuse-cxa-atexit">, Group<f_Group>;
def fverbose_asm : Flag<"-fverbose-asm">, Group<f_Group>;
def fvisibility_EQ : Joined<"-fvisibility=">, Group<f_Group>;
-def fvisibility_inlines_hidden : Flag<"-fvisibility-inlines-hidden">, Group<f_Group>;
-def fwrapv : Flag<"-fwrapv">, Group<f_Group>;
-def fwritable_strings : Flag<"-fwritable-strings">, Group<f_Group>;
+def fvisibility_inlines_hidden : Flag<"-fvisibility-inlines-hidden">, Group<f_Group>,
+ HelpText<"Give inline C++ member functions default visibility by default">,
+ Flags<[CC1Option]>;
+def fwrapv : Flag<"-fwrapv">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Treat signed integer overflow as two's complement">;
+def fwritable_strings : Flag<"-fwritable-strings">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Store string literals as writable data">;
def fzero_initialized_in_bss : Flag<"-fzero-initialized-in-bss">, Group<f_Group>;
-def ffunction_sections: Flag <"-ffunction-sections">, Group<f_Group>;
-def fdata_sections : Flag <"-fdata-sections">, Group<f_Group>;
+def ffunction_sections: Flag <"-ffunction-sections">, Group<f_Group>,
+ Flags<[CC1Option]>, HelpText<"Place each function in its own section (ELF Only)">;
+def fdata_sections : Flag <"-fdata-sections">, Group<f_Group>, Flags<[CC1Option]>,
+ HelpText<"Place each data in its own section (ELF Only)">;
def f : Joined<"-f">, Group<f_Group>;
def g0 : Flag<"-g0">, Group<g_Group>;
def g2 : Flag<"-g2">, Group<g_Group>;
@@ -565,32 +671,54 @@
def gstabs1 : Flag<"-gstabs1">, Group<g_Group>;
def gstabs2 : Flag<"-gstabs2">, Group<g_Group>;
def gused : Flag<"-gused">, Group<g_Group>;
-def g_Flag : Flag<"-g">, Group<g_Group>;
+def g_Flag : Flag<"-g">, Group<g_Group>, HelpText<"Generate source level debug information">,
+ Flags<[CC1Option]>;
+def gline_tables_only : Flag<"-gline-tables-only">, Group<g_Group>,
+ HelpText<"Emit debug line number tables only">, Flags<[CC1Option]>;
def headerpad__max__install__names : Joined<"-headerpad_max_install_names">;
-def index_header_map : Flag<"-index-header-map">;
-def idirafter : JoinedOrSeparate<"-idirafter">, Group<clang_i_Group>;
-def iframework : Joined<"-iframework">, Group<clang_i_Group>;
-def imacros : JoinedOrSeparate<"-imacros">, Group<clang_i_Group>;
+def help : Flag<"-help">, Flags<[CC1Option]>,
+ HelpText<"Display available options">;
+def index_header_map : Flag<"-index-header-map">, Flags<[CC1Option]>,
+ HelpText<"Make the next included directory (-I or -F) an indexer header map">;
+def idirafter : JoinedOrSeparate<"-idirafter">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Add directory to AFTER include search path">;
+def iframework : Joined<"-iframework">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Add directory to SYSTEM framework search path">;
+def imacros : JoinedOrSeparate<"-imacros">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Include macros from file before parsing">, MetaVarName<"<file>">;
def image__base : Separate<"-image_base">;
-def include_ : JoinedOrSeparate<"-include">, Group<clang_i_Group>, EnumName<"include">;
-def include_pch : Separate<"-include-pch">, Group<clang_i_Group>;
+def include_ : JoinedOrSeparate<"-include">, Group<clang_i_Group>, EnumName<"include">,
+ MetaVarName<"<file>">, HelpText<"Include file before parsing">, Flags<[CC1Option]>;
+def include_pch : Separate<"-include-pch">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Include precompiled header file">, MetaVarName<"<file>">;
def init : Separate<"-init">;
def install__name : Separate<"-install_name">;
def integrated_as : Flag<"-integrated-as">, Flags<[DriverOption]>;
-def iprefix : JoinedOrSeparate<"-iprefix">, Group<clang_i_Group>;
-def iquote : JoinedOrSeparate<"-iquote">, Group<clang_i_Group>;
-def isysroot : JoinedOrSeparate<"-isysroot">, Group<clang_i_Group>;
-def isystem : JoinedOrSeparate<"-isystem">, Group<clang_i_Group>;
-def iwithprefixbefore : JoinedOrSeparate<"-iwithprefixbefore">, Group<clang_i_Group>;
-def iwithprefix : JoinedOrSeparate<"-iwithprefix">, Group<clang_i_Group>;
-def iwithsysroot : JoinedOrSeparate<"-iwithsysroot">, Group<clang_i_Group>;
+def iprefix : JoinedOrSeparate<"-iprefix">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Set the -iwithprefix/-iwithprefixbefore prefix">, MetaVarName<"<dir>">;
+def iquote : JoinedOrSeparate<"-iquote">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Add directory to QUOTE include search path">, MetaVarName<"<directory>">;
+def isysroot : JoinedOrSeparate<"-isysroot">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Set the system root directory (usually /)">, MetaVarName<"<dir>">;
+def isystem : JoinedOrSeparate<"-isystem">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Add directory to SYSTEM include search path">, MetaVarName<"<directory>">;
+def iwithprefixbefore : JoinedOrSeparate<"-iwithprefixbefore">, Group<clang_i_Group>,
+ HelpText<"Set directory to include search path with prefix">, MetaVarName<"<dir>">,
+ Flags<[CC1Option]>;
+def iwithprefix : JoinedOrSeparate<"-iwithprefix">, Group<clang_i_Group>, Flags<[CC1Option]>,
+ HelpText<"Set directory to SYSTEM include search path with prefix">, MetaVarName<"<dir>">;
+def iwithsysroot : JoinedOrSeparate<"-iwithsysroot">, Group<clang_i_Group>,
+ HelpText<"Add directory to SYSTEM include search path, "
+ "absolute paths are relative to -isysroot">, MetaVarName<"<directory>">,
+ Flags<[CC1Option]>;
def i : Joined<"-i">, Group<i_Group>;
def keep__private__externs : Flag<"-keep_private_externs">;
def l : JoinedOrSeparate<"-l">, Flags<[LinkerInput, RenderJoined]>;
def lazy__framework : Separate<"-lazy_framework">, Flags<[LinkerInput]>;
def lazy__library : Separate<"-lazy_library">, Flags<[LinkerInput]>;
def m32 : Flag<"-m32">, Group<m_Group>, Flags<[DriverOption]>;
-def mqdsp6_compat : Flag<"-mqdsp6-compat">, Group<m_Group>, Flags<[DriverOption]>;
+def mqdsp6_compat : Flag<"-mqdsp6-compat">, Group<m_Group>, Flags<[DriverOption,CC1Option]>,
+ HelpText<"Enable hexagon-qdsp6 backward compatibility">;
def m3dnowa : Flag<"-m3dnowa">, Group<m_x86_Features_Group>;
def m3dnow : Flag<"-m3dnow">, Group<m_x86_Features_Group>;
def m64 : Flag<"-m64">, Group<m_Group>, Flags<[DriverOption]>;
@@ -611,16 +739,21 @@
def mios_simulator_version_min_EQ : Joined<"-mios-simulator-version-min=">, Group<m_Group>;
def mkernel : Flag<"-mkernel">, Group<m_Group>;
def mlinker_version_EQ : Joined<"-mlinker-version=">, Flags<[NoForward]>;
-def mllvm : Separate<"-mllvm">;
+def mllvm : Separate<"-mllvm">, Flags<[CC1Option]>,
+ HelpText<"Additional arguments to forward to LLVM's option processing">;
def mmacosx_version_min_EQ : Joined<"-mmacosx-version-min=">, Group<m_Group>;
-def mms_bitfields : Flag<"-mms-bitfields">, Group<m_Group>;
-def mstackrealign : Flag<"-mstackrealign">, Group<m_Group>;
-def mstack_alignment : Joined<"-mstack-alignment=">, Group<m_Group>;
+def mms_bitfields : Flag<"-mms-bitfields">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"Set the default structure layout to be compatible with the Microsoft compiler standard.">;
+def mstackrealign : Flag<"-mstackrealign">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"Force realign the stack at entry to every function.">;
+def mstack_alignment : Joined<"-mstack-alignment=">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"Set the stack alignment">;
def mmmx : Flag<"-mmmx">, Group<m_x86_Features_Group>;
def mno_3dnowa : Flag<"-mno-3dnowa">, Group<m_x86_Features_Group>;
def mno_3dnow : Flag<"-mno-3dnow">, Group<m_x86_Features_Group>;
def mno_constant_cfstrings : Flag<"-mno-constant-cfstrings">, Group<m_Group>;
-def mno_global_merge : Flag<"-mno-global-merge">, Group<m_Group>;
+def mno_global_merge : Flag<"-mno-global-merge">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"Disable merging of globals">;
def mno_mmx : Flag<"-mno-mmx">, Group<m_x86_Features_Group>;
def mno_pascal_strings : Flag<"-mno-pascal-strings">, Group<m_Group>;
def mno_red_zone : Flag<"-mno-red-zone">, Group<m_Group>;
@@ -650,14 +783,18 @@
def mno_warn_nonportable_cfstrings : Flag<"-mno-warn-nonportable-cfstrings">, Group<m_Group>;
def mno_omit_leaf_frame_pointer : Flag<"-mno-omit-leaf-frame-pointer">, Group<f_Group>;
-def momit_leaf_frame_pointer : Flag<"-momit-leaf-frame-pointer">, Group<f_Group>;
+def momit_leaf_frame_pointer : Flag<"-momit-leaf-frame-pointer">, Group<f_Group>,
+ HelpText<"Omit frame pointer setup for leaf functions.">, Flags<[CC1Option]>;
def mpascal_strings : Flag<"-mpascal-strings">, Group<m_Group>;
def mred_zone : Flag<"-mred-zone">, Group<m_Group>;
def mregparm_EQ : Joined<"-mregparm=">, Group<m_Group>;
-def mrelax_all : Flag<"-mrelax-all">, Group<m_Group>;
-def mrtd: Flag<"-mrtd">, Group<m_Group>;
+def mrelax_all : Flag<"-mrelax-all">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"(integrated-as) Relax all machine instructions">;
+def mrtd : Flag<"-mrtd">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"Make StdCall calling convention the default">;
def msmall_data_threshold_EQ : Joined <"-msmall-data-threshold=">, Group<m_Group>;
-def msoft_float : Flag<"-msoft-float">, Group<m_Group>;
+def msoft_float : Flag<"-msoft-float">, Group<m_Group>, Flags<[CC1Option]>,
+ HelpText<"Use software floating point">;
def msse2 : Flag<"-msse2">, Group<m_x86_Features_Group>;
def msse3 : Flag<"-msse3">, Group<m_x86_Features_Group>;
def msse4a : Flag<"-msse4a">, Group<m_x86_Features_Group>;
@@ -688,7 +825,8 @@
def no_integrated_as : Flag<"-no-integrated-as">, Flags<[DriverOption]>;
def no_integrated_cpp : Flag<"-no-integrated-cpp">, Flags<[DriverOption]>;
def no__dead__strip__inits__and__terms : Flag<"-no_dead_strip_inits_and_terms">;
-def nobuiltininc : Flag<"-nobuiltininc">;
+def nobuiltininc : Flag<"-nobuiltininc">, Flags<[CC1Option]>,
+ HelpText<"Disable builtin #include directories">;
def nodefaultlibs : Flag<"-nodefaultlibs">;
def nofixprebinding : Flag<"-nofixprebinding">;
def nolibc : Flag<"-nolibc">;
@@ -698,16 +836,17 @@
def nostartfiles : Flag<"-nostartfiles">;
def nostdinc : Flag<"-nostdinc">;
def nostdlibinc : Flag<"-nostdlibinc">;
-def nostdincxx : Flag<"-nostdinc++">;
+def nostdincxx : Flag<"-nostdinc++">, Flags<[CC1Option]>,
+ HelpText<"Disable standard #include directories for the C++ standard library">;
def nostdlib : Flag<"-nostdlib">;
def object : Flag<"-object">;
-def o : JoinedOrSeparate<"-o">, Flags<[DriverOption, RenderAsInput]>,
+def o : JoinedOrSeparate<"-o">, Flags<[DriverOption, RenderAsInput, CC1Option]>,
HelpText<"Write output to <file>">, MetaVarName<"<file>">;
def pagezero__size : JoinedOrSeparate<"-pagezero_size">;
def pass_exit_codes : Flag<"-pass-exit-codes">, Flags<[Unsupported]>;
-def pedantic_errors : Flag<"-pedantic-errors">, Group<pedantic_Group>;
-def pedantic : Flag<"-pedantic">, Group<pedantic_Group>;
-def pg : Flag<"-pg">;
+def pedantic_errors : Flag<"-pedantic-errors">, Group<pedantic_Group>, Flags<[CC1Option]>;
+def pedantic : Flag<"-pedantic">, Group<pedantic_Group>, Flags<[CC1Option]>;
+def pg : Flag<"-pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC1Option]>;
def pipe : Flag<"-pipe">,
HelpText<"Use pipes between commands, when possible">;
def prebind__all__twolevel__modules : Flag<"-prebind_all_twolevel_modules">;
@@ -715,7 +854,8 @@
def preload : Flag<"-preload">;
def print_file_name_EQ : Joined<"-print-file-name=">,
HelpText<"Print the full library path of <file>">, MetaVarName<"<file>">;
-def print_ivar_layout : Flag<"-print-ivar-layout">;
+def print_ivar_layout : Flag<"-print-ivar-layout">, Flags<[CC1Option]>,
+ HelpText<"Enable Objective-C Ivar layout bitmap print trace">;
def print_libgcc_file_name : Flag<"-print-libgcc-file-name">,
HelpText<"Print the library path for \"libgcc.a\"">;
def print_multi_directory : Flag<"-print-multi-directory">;
@@ -727,13 +867,14 @@
HelpText<"Print the paths used for finding libraries and programs">;
def private__bundle : Flag<"-private_bundle">;
def pthreads : Flag<"-pthreads">;
-def pthread : Flag<"-pthread">;
+def pthread : Flag<"-pthread">, Flags<[CC1Option]>,
+ HelpText<"Support POSIX threads in generated code">;
def p : Flag<"-p">;
def pie : Flag<"-pie">;
def read__only__relocs : Separate<"-read_only_relocs">;
def remap : Flag<"-remap">;
-def rewrite_objc : Flag<"-rewrite-objc">, Flags<[DriverOption]>,
- HelpText<"Rewrite Objective-C source to C++">;
+def rewrite_objc : Flag<"-rewrite-objc">, Flags<[DriverOption,CC1Option]>,
+ HelpText<"Rewrite Objective-C source to C++">, Group<Action_Group>;
def rewrite_legacy_objc : Flag<"-rewrite-legacy-objc">, Flags<[DriverOption]>,
HelpText<"Rewrite Legacy Objective-C source to C++">;
def rdynamic : Flag<"-rdynamic">;
@@ -765,8 +906,10 @@
def static_libstdcxx : Flag<"-static-libstdc++">;
def static : Flag<"-static">, Flags<[NoArgumentUnused]>;
def std_default_EQ : Joined<"-std-default=">;
-def std_EQ : Joined<"-std=">, Group<L_Group>;
-def stdlib_EQ : Joined<"-stdlib=">;
+def std_EQ : Joined<"-std=">, Flags<[CC1Option]>, Group<L_Group>,
+ HelpText<"Language standard to compile for">;
+def stdlib_EQ : Joined<"-stdlib=">, Flags<[CC1Option]>,
+ HelpText<"C++ standard library to use">;
def sub__library : JoinedOrSeparate<"-sub_library">;
def sub__umbrella : JoinedOrSeparate<"-sub_umbrella">;
def s : Flag<"-s">;
@@ -778,21 +921,24 @@
def ccc_host_triple : Separate<"-ccc-host-triple">, Alias<target>;
def time : Flag<"-time">,
HelpText<"Time individual commands">;
-def traditional_cpp : Flag<"-traditional-cpp">;
+def traditional_cpp : Flag<"-traditional-cpp">, Flags<[CC1Option]>,
+ HelpText<"Enable some traditional CPP emulation">;
def traditional : Flag<"-traditional">;
-def trigraphs : Flag<"-trigraphs">;
+def trigraphs : Flag<"-trigraphs">, Flags<[CC1Option]>,
+ HelpText<"Process trigraph sequences">;
def twolevel__namespace__hints : Flag<"-twolevel_namespace_hints">;
def twolevel__namespace : Flag<"-twolevel_namespace">;
def t : Flag<"-t">;
def umbrella : Separate<"-umbrella">;
def undefined : JoinedOrSeparate<"-undefined">, Group<u_Group>;
-def undef : Flag<"-undef">, Group<u_Group>;
+def undef : Flag<"-undef">, Group<u_Group>, Flags<[CC1Option]>,
+ HelpText<"undef all system defines">;
def unexported__symbols__list : Separate<"-unexported_symbols_list">;
def u : JoinedOrSeparate<"-u">, Group<u_Group>;
def use_gold_plugin : Flag<"-use-gold-plugin">;
-def v : Flag<"-v">,
+def v : Flag<"-v">, Flags<[CC1Option]>,
HelpText<"Show commands to run and use verbose output">;
-def verify : Flag<"-verify">, Flags<[DriverOption]>,
+def verify : Flag<"-verify">, Flags<[DriverOption,CC1Option]>,
HelpText<"Verify output using a verifier.">;
def weak_l : Joined<"-weak-l">, Flags<[LinkerInput]>;
def weak__framework : Separate<"-weak_framework">, Flags<[LinkerInput]>;
@@ -800,15 +946,15 @@
def weak__reference__mismatches : Separate<"-weak_reference_mismatches">;
def whatsloaded : Flag<"-whatsloaded">;
def whyload : Flag<"-whyload">;
-def w : Flag<"-w">;
-def x : JoinedOrSeparate<"-x">, Flags<[DriverOption]>,
+def w : Flag<"-w">, HelpText<"Suppress all warnings.">, Flags<[CC1Option]>;
+def x : JoinedOrSeparate<"-x">, Flags<[DriverOption,CC1Option]>,
HelpText<"Treat subsequent input files as having type <language>">,
MetaVarName<"<language>">;
def y : Joined<"-y">;
-def working_directory : Separate<"-working-directory">,
+def working_directory : JoinedOrSeparate<"-working-directory">, Flags<[CC1Option]>,
HelpText<"Resolve file paths relative to the specified directory">;
-def working_directory_EQ : Joined<"-working-directory=">,
+def working_directory_EQ : Joined<"-working-directory=">, Flags<[CC1Option]>,
Alias<working_directory>;
// Double dash options, which are usually an alias for one of the previous
@@ -852,8 +998,7 @@
def _force_link_EQ : Joined<"--force-link=">, Alias<u>;
def _force_link : Separate<"--force-link">, Alias<u>;
def _help_hidden : Flag<"--help-hidden">;
-def _help : Flag<"--help">,
- HelpText<"Display available options">;
+def _help : Flag<"--help">, Alias<help>;
def _imacros_EQ : Joined<"--imacros=">, Alias<imacros>;
def _imacros : Separate<"--imacros">, Alias<imacros>;
def _include_barrier : Flag<"--include-barrier">, Alias<I_>;
@@ -943,7 +1088,7 @@
def _unsigned_char : Flag<"--unsigned-char">, Alias<funsigned_char>;
def _user_dependencies : Flag<"--user-dependencies">, Alias<MM>;
def _verbose : Flag<"--verbose">, Alias<v>;
-def _version : Flag<"--version">;
+def _version : Flag<"--version">, Flags<[CC1Option]>;
def _warn__EQ : Joined<"--warn-=">, Alias<W_Joined>;
def _warn_ : Joined<"--warn-">, Alias<W_Joined>;
def _write_dependencies : Flag<"--write-dependencies">, Alias<MD>;
@@ -963,3 +1108,5 @@
Flags<[LinkerInput, NoArgumentUnused, Unsupported]>, Group<reserved_lib_Group>;
def Z_reserved_lib_cckext : Flag<"-Z-reserved-lib-cckext">,
Flags<[LinkerInput, NoArgumentUnused, Unsupported]>, Group<reserved_lib_Group>;
+
+include "CC1Options.td"
Modified: cfe/branches/tooling/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Driver/ToolChain.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Driver/ToolChain.h (original)
+++ cfe/branches/tooling/include/clang/Driver/ToolChain.h Tue May 8 03:47:31 2012
@@ -137,6 +137,9 @@
/// default.
virtual bool IsStrictAliasingDefault() const { return true; }
+ /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
+ virtual bool IsMathErrnoDefault() const { return true; }
+
/// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
/// -fobjc-default-synthesize-properties by default.
virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
Modified: cfe/branches/tooling/include/clang/Frontend/CodeGenOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Frontend/CodeGenOptions.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/branches/tooling/include/clang/Frontend/CodeGenOptions.h Tue May 8 03:47:31 2012
@@ -35,84 +35,91 @@
Mixed = 2
};
- unsigned AsmVerbose : 1; /// -dA, -fverbose-asm.
- unsigned ObjCAutoRefCountExceptions : 1; /// Whether ARC should be EH-safe.
- unsigned CUDAIsDevice : 1; /// Set when compiling for CUDA device.
- unsigned CXAAtExit : 1; /// Use __cxa_atexit for calling destructors.
- unsigned CXXCtorDtorAliases: 1; /// Emit complete ctors/dtors as linker
- /// aliases to base ctors when possible.
- unsigned DataSections : 1; /// Set when -fdata-sections is enabled
- unsigned DebugInfo : 1; /// Should generate debug info (-g).
- unsigned LimitDebugInfo : 1; /// Limit generated debug info to reduce size.
- unsigned DisableFPElim : 1; /// Set when -fomit-frame-pointer is enabled.
- unsigned DisableLLVMOpts : 1; /// Don't run any optimizations, for use in
- /// getting .bc files that correspond to the
- /// internal state before optimizations are
- /// done.
- unsigned DisableRedZone : 1; /// Set when -mno-red-zone is enabled.
- unsigned DisableTailCalls : 1; /// Do not emit tail calls.
- unsigned EmitDeclMetadata : 1; /// Emit special metadata indicating what
- /// Decl* various IR entities came from. Only
- /// useful when running CodeGen as a
- /// subroutine.
- unsigned EmitGcovArcs : 1; /// Emit coverage data files, aka. GCDA.
- unsigned EmitGcovNotes : 1; /// Emit coverage "notes" files, aka GCNO.
- 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
- unsigned HiddenWeakVTables : 1; /// Emit weak vtables, RTTI, and thunks with
- /// hidden visibility.
- unsigned InstrumentFunctions : 1; /// Set when -finstrument-functions is
- /// enabled.
- unsigned InstrumentForProfiling : 1; /// Set when -pg is enabled
- unsigned LessPreciseFPMAD : 1; /// Enable less precise MAD instructions to be
- /// generated.
- unsigned MergeAllConstants : 1; /// Merge identical constants.
- unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
- unsigned NoDwarf2CFIAsm : 1; /// Set when -fno-dwarf2-cfi-asm is enabled.
- unsigned NoDwarfDirectoryAsm : 1; /// Set when -fno-dwarf-directory-asm is
- /// enabled.
- unsigned NoExecStack : 1; /// Set when -Wa,--noexecstack is enabled.
- unsigned NoGlobalMerge : 1; /// Set when -mno-global-merge is enabled.
- unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled.
- unsigned NoInfsFPMath : 1; /// Assume FP arguments, results not +-Inf.
- unsigned NoInline : 1; /// Set when -fno-inline is enabled. Disables
- /// use of the inline keyword.
- unsigned NoNaNsFPMath : 1; /// Assume FP arguments, results not NaN.
- unsigned NoZeroInitializedInBSS : 1; /// -fno-zero-initialized-in-bss
- unsigned ObjCDispatchMethod : 2; /// Method of Objective-C dispatch to use.
- unsigned ObjCRuntimeHasARC : 1; /// The target runtime supports ARC natively
- unsigned ObjCRuntimeHasTerminate : 1; /// The ObjC runtime has objc_terminate
- unsigned OmitLeafFramePointer : 1; /// Set when -momit-leaf-frame-pointer is
- /// enabled.
- unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.
- unsigned OptimizeSize : 2; /// If -Os (==1) or -Oz (==2) is specified.
- unsigned RelaxAll : 1; /// Relax all machine code instructions.
- unsigned RelaxedAliasing : 1; /// Set when -fno-strict-aliasing is enabled.
- unsigned SaveTempLabels : 1; /// Save temporary labels.
- unsigned SimplifyLibCalls : 1; /// Set when -fbuiltin is enabled.
- unsigned SoftFloat : 1; /// -soft-float.
- unsigned StrictEnums : 1; /// Optimize based on strict enum definition.
- unsigned TimePasses : 1; /// Set when -ftime-report is enabled.
- unsigned UnitAtATime : 1; /// Unused. For mirroring GCC optimization
+ enum DebugInfoKind {
+ NoDebugInfo, // Don't generate debug info.
+ DebugLineTablesOnly, // Emit only debug info necessary for generating
+ // line number tables (-gline-tables-only).
+ LimitedDebugInfo, // Limit generated debug info to reduce size
+ // (-flimit-debug-info).
+ FullDebugInfo // Generate complete debug info.
+ };
+
+ unsigned AsmVerbose : 1; ///< -dA, -fverbose-asm.
+ unsigned ObjCAutoRefCountExceptions : 1; ///< Whether ARC should be EH-safe.
+ unsigned CUDAIsDevice : 1; ///< Set when compiling for CUDA device.
+ unsigned CXAAtExit : 1; ///< Use __cxa_atexit for calling destructors.
+ unsigned CXXCtorDtorAliases: 1; ///< Emit complete ctors/dtors as linker
+ ///< aliases to base ctors when possible.
+ unsigned DataSections : 1; ///< Set when -fdata-sections is enabled
+ unsigned DisableFPElim : 1; ///< Set when -fomit-frame-pointer is enabled.
+ unsigned DisableLLVMOpts : 1; ///< Don't run any optimizations, for use in
+ ///< getting .bc files that correspond to the
+ ///< internal state before optimizations are
+ ///< done.
+ unsigned DisableRedZone : 1; ///< Set when -mno-red-zone is enabled.
+ unsigned DisableTailCalls : 1; ///< Do not emit tail calls.
+ unsigned EmitDeclMetadata : 1; ///< Emit special metadata indicating what
+ ///< Decl* various IR entities came from. Only
+ ///< useful when running CodeGen as a
+ ///< subroutine.
+ unsigned EmitGcovArcs : 1; ///< Emit coverage data files, aka. GCDA.
+ unsigned EmitGcovNotes : 1; ///< Emit coverage "notes" files, aka GCNO.
+ 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
+ unsigned HiddenWeakVTables : 1; ///< Emit weak vtables, RTTI, and thunks with
+ ///< hidden visibility.
+ unsigned InstrumentFunctions : 1; ///< Set when -finstrument-functions is
+ ///< enabled.
+ unsigned InstrumentForProfiling : 1; ///< Set when -pg is enabled
+ unsigned LessPreciseFPMAD : 1; ///< Enable less precise MAD instructions to
+ ///< be generated.
+ unsigned MergeAllConstants : 1; ///< Merge identical constants.
+ unsigned NoCommon : 1; ///< Set when -fno-common or C++ is enabled.
+ unsigned NoDwarf2CFIAsm : 1; ///< Set when -fno-dwarf2-cfi-asm is enabled.
+ unsigned NoDwarfDirectoryAsm : 1; ///< Set when -fno-dwarf-directory-asm is
+ ///< enabled.
+ unsigned NoExecStack : 1; ///< Set when -Wa,--noexecstack is enabled.
+ unsigned NoGlobalMerge : 1; ///< Set when -mno-global-merge is enabled.
+ unsigned NoImplicitFloat : 1; ///< Set when -mno-implicit-float is enabled.
+ unsigned NoInfsFPMath : 1; ///< Assume FP arguments, results not +-Inf.
+ unsigned NoInline : 1; ///< Set when -fno-inline is enabled. Disables
+ ///< use of the inline keyword.
+ unsigned NoNaNsFPMath : 1; ///< Assume FP arguments, results not NaN.
+ unsigned NoZeroInitializedInBSS : 1; ///< -fno-zero-initialized-in-bss
+ unsigned ObjCDispatchMethod : 2; ///< Method of Objective-C dispatch to use.
+ unsigned ObjCRuntimeHasARC : 1; ///< The target runtime supports ARC natively
+ unsigned ObjCRuntimeHasTerminate : 1; ///< The ObjC runtime has objc_terminate
+ unsigned OmitLeafFramePointer : 1; ///< Set when -momit-leaf-frame-pointer is
+ ///< enabled.
+ unsigned OptimizationLevel : 3; ///< The -O[0-4] option specified.
+ unsigned OptimizeSize : 2; ///< If -Os (==1) or -Oz (==2) is specified.
+ unsigned RelaxAll : 1; ///< Relax all machine code instructions.
+ unsigned RelaxedAliasing : 1; ///< Set when -fno-strict-aliasing is enabled.
+ unsigned SaveTempLabels : 1; ///< Save temporary labels.
+ unsigned SimplifyLibCalls : 1; ///< Set when -fbuiltin is enabled.
+ unsigned SoftFloat : 1; ///< -soft-float.
+ unsigned StrictEnums : 1; ///< Optimize based on strict enum definition.
+ unsigned TimePasses : 1; ///< Set when -ftime-report is enabled.
+ unsigned UnitAtATime : 1; ///< Unused. For mirroring GCC optimization
/// selection.
- unsigned UnrollLoops : 1; /// Control whether loops are unrolled.
- unsigned UnsafeFPMath : 1; /// Allow unsafe floating point optzns.
- unsigned UnwindTables : 1; /// Emit unwind tables.
+ unsigned UnrollLoops : 1; ///< Control whether loops are unrolled.
+ unsigned UnsafeFPMath : 1; ///< Allow unsafe floating point optzns.
+ unsigned UnwindTables : 1; ///< Emit unwind tables.
/// Attempt to use register sized accesses to bit-fields in structures, when
/// possible.
unsigned UseRegisterSizedBitfieldAccess : 1;
- unsigned VerifyModule : 1; /// Control whether the module should be run
- /// through the LLVM Verifier.
+ unsigned VerifyModule : 1; ///< Control whether the module should be run
+ ///< through the LLVM Verifier.
- unsigned StackRealignment : 1; /// Control whether to permit stack
- /// realignment.
- unsigned StackAlignment; /// Overrides default stack alignment,
- /// if not 0.
+ unsigned StackRealignment : 1; ///< Control whether to permit stack
+ ///< realignment.
+ unsigned StackAlignment; ///< Overrides default stack alignment,
+ ///< if not 0.
/// The code model to use (-mcmodel).
std::string CodeModel;
@@ -127,6 +134,9 @@
/// The string to embed in debug information as the current working directory.
std::string DebugCompilationDir;
+ /// The kind of generated debug info.
+ DebugInfoKind DebugInfo;
+
/// The string to embed in the debug information for the compile unit, if
/// non-empty.
std::string DwarfDebugFlags;
@@ -169,8 +179,6 @@
CXAAtExit = 1;
CXXCtorDtorAliases = 0;
DataSections = 0;
- DebugInfo = 0;
- LimitDebugInfo = 0;
DisableFPElim = 0;
DisableLLVMOpts = 0;
DisableRedZone = 0;
@@ -217,6 +225,7 @@
StackRealignment = 0;
StackAlignment = 0;
+ DebugInfo = NoDebugInfo;
Inlining = NoInlining;
RelocationModel = "pic";
}
Modified: cfe/branches/tooling/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Lex/Lexer.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Lex/Lexer.h (original)
+++ cfe/branches/tooling/include/clang/Lex/Lexer.h Tue May 8 03:47:31 2012
@@ -335,6 +335,28 @@
///
/// Returns a null range if a part of the range resides inside a macro
/// expansion or the range does not reside on the same FileID.
+ ///
+ /// This function is trying to deal with macros and return a range based on
+ /// file locations. The cases where it can successfully handle macros are:
+ ///
+ /// -begin or end range lies at the start or end of a macro expansion, in
+ /// which case the location will be set to the expansion point, e.g:
+ /// #define M 1 2
+ /// a M
+ /// If you have a range [a, 2] (where 2 came from the macro), the function
+ /// will return a range for "a M"
+ /// if you have range [a, 1], the function will fail because the range
+ /// overlaps with only a part of the macro
+ ///
+ /// -The macro is a function macro and the range can be mapped to the macro
+ /// arguments, e.g:
+ /// #define M 1 2
+ /// #define FM(x) x
+ /// FM(a b M)
+ /// if you have range [b, 2], the function will return the file range "b M"
+ /// inside the macro arguments.
+ /// if you have range [a, 2], the function will return the file range
+ /// "FM(a b M)" since the range includes all of the macro expansion.
static CharSourceRange makeFileCharRange(CharSourceRange Range,
const SourceManager &SM,
const LangOptions &LangOpts);
Modified: cfe/branches/tooling/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Lex/LiteralSupport.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/branches/tooling/include/clang/Lex/LiteralSupport.h Tue May 8 03:47:31 2012
@@ -232,6 +232,7 @@
void init(const Token *StringToks, unsigned NumStringToks);
bool CopyStringFragment(StringRef Fragment);
bool DiagnoseBadString(const Token& Tok);
+ void DiagnoseLexingError(SourceLocation Loc);
};
} // end namespace clang
Modified: cfe/branches/tooling/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Parse/Parser.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Parse/Parser.h (original)
+++ cfe/branches/tooling/include/clang/Parse/Parser.h Tue May 8 03:47:31 2012
@@ -31,6 +31,9 @@
class DeclGroupRef;
class DiagnosticBuilder;
class Parser;
+ class ParsingDeclRAIIObject;
+ class ParsingDeclSpec;
+ class ParsingDeclarator;
class PragmaUnusedHandler;
class ColonProtectionRAIIObject;
class InMessageExpressionRAIIObject;
@@ -207,6 +210,7 @@
const TargetInfo &getTargetInfo() const { return PP.getTargetInfo(); }
Preprocessor &getPreprocessor() const { return PP; }
Sema &getActions() const { return Actions; }
+ AttributeFactory &getAttrFactory() { return AttrFactory; }
const Token &getCurToken() const { return Tok; }
Scope *getCurScope() const { return Actions.getCurScope(); }
@@ -451,7 +455,7 @@
}
}
- enum { MaxDepth = 256 };
+ enum { MaxDepth = 512 };
bool diagnoseOverflow();
bool diagnoseMissingClose();
@@ -584,11 +588,15 @@
class TentativeParsingAction {
Parser &P;
Token PrevTok;
+ unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount;
bool isActive;
public:
explicit TentativeParsingAction(Parser& p) : P(p) {
PrevTok = P.Tok;
+ PrevParenCount = P.ParenCount;
+ PrevBracketCount = P.BracketCount;
+ PrevBraceCount = P.BraceCount;
P.PP.EnableBacktrackAtThisPos();
isActive = true;
}
@@ -601,6 +609,9 @@
assert(isActive && "Parsing action was finished!");
P.PP.Backtrack();
P.Tok = PrevTok;
+ P.ParenCount = PrevParenCount;
+ P.BracketCount = PrevBracketCount;
+ P.BraceCount = PrevBraceCount;
isActive = false;
}
~TentativeParsingAction() {
@@ -944,120 +955,7 @@
return *ClassStack.top();
}
- /// \brief RAII object used to inform the actions that we're
- /// currently parsing a declaration. This is active when parsing a
- /// variable's initializer, but not when parsing the body of a
- /// class or function definition.
- class ParsingDeclRAIIObject {
- Sema &Actions;
- Sema::ParsingDeclState State;
- bool Popped;
-
- public:
- ParsingDeclRAIIObject(Parser &P) : Actions(P.Actions) {
- push();
- }
-
- ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *Other)
- : Actions(P.Actions) {
- if (Other) steal(*Other);
- else push();
- }
-
- /// Creates a RAII object which steals the state from a different
- /// object instead of pushing.
- ParsingDeclRAIIObject(ParsingDeclRAIIObject &Other)
- : Actions(Other.Actions) {
- steal(Other);
- }
-
- ~ParsingDeclRAIIObject() {
- abort();
- }
-
- /// Resets the RAII object for a new declaration.
- void reset() {
- abort();
- push();
- }
-
- /// Signals that the context was completed without an appropriate
- /// declaration being parsed.
- void abort() {
- pop(0);
- }
-
- void complete(Decl *D) {
- assert(!Popped && "ParsingDeclaration has already been popped!");
- pop(D);
- }
-
- private:
- void steal(ParsingDeclRAIIObject &Other) {
- State = Other.State;
- Popped = Other.Popped;
- Other.Popped = true;
- }
-
- void push() {
- State = Actions.PushParsingDeclaration();
- Popped = false;
- }
-
- void pop(Decl *D) {
- if (!Popped) {
- Actions.PopParsingDeclaration(State, D);
- Popped = true;
- }
- }
- };
-
- /// A class for parsing a DeclSpec.
- class ParsingDeclSpec : public DeclSpec {
- ParsingDeclRAIIObject ParsingRAII;
-
- public:
- ParsingDeclSpec(Parser &P) : DeclSpec(P.AttrFactory), ParsingRAII(P) {}
- ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
- : DeclSpec(P.AttrFactory), ParsingRAII(P, RAII) {}
-
- void complete(Decl *D) {
- ParsingRAII.complete(D);
- }
-
- void abort() {
- ParsingRAII.abort();
- }
- };
-
- /// A class for parsing a declarator.
- class ParsingDeclarator : public Declarator {
- ParsingDeclRAIIObject ParsingRAII;
-
- public:
- ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
- : Declarator(DS, C), ParsingRAII(P) {
- }
-
- const ParsingDeclSpec &getDeclSpec() const {
- return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
- }
-
- ParsingDeclSpec &getMutableDeclSpec() const {
- return const_cast<ParsingDeclSpec&>(getDeclSpec());
- }
-
- void clear() {
- Declarator::clear();
- ParsingRAII.reset();
- }
-
- void complete(Decl *D) {
- ParsingRAII.complete(D);
- }
- };
-
- /// \brief RAII object used to
+ /// \brief RAII object used to manage the parsing of a class definition.
class ParsingClassDefinition {
Parser &P;
bool Popped;
@@ -1422,12 +1320,10 @@
ExprResult ParseThrowExpression();
ExceptionSpecificationType tryParseExceptionSpecification(
- bool Delayed,
SourceRange &SpecificationRange,
SmallVectorImpl<ParsedType> &DynamicExceptions,
SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
- ExprResult &NoexceptExpr,
- CachedTokens *&ExceptionSpecTokens);
+ ExprResult &NoexceptExpr);
// EndLoc is filled with the location of the last token of the specification.
ExceptionSpecificationType ParseDynamicExceptionSpecification(
Modified: cfe/branches/tooling/include/clang/Rewrite/TokenRewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Rewrite/TokenRewriter.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Rewrite/TokenRewriter.h (original)
+++ cfe/branches/tooling/include/clang/Rewrite/TokenRewriter.h Tue May 8 03:47:31 2012
@@ -16,12 +16,12 @@
#define LLVM_CLANG_TOKENREWRITER_H
#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Token.h"
#include "llvm/ADT/OwningPtr.h"
#include <list>
#include <map>
namespace clang {
- class Token;
class LangOptions;
class ScratchBuffer;
Modified: cfe/branches/tooling/include/clang/Sema/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Sema/AttributeList.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Sema/AttributeList.h (original)
+++ cfe/branches/tooling/include/clang/Sema/AttributeList.h Tue May 8 03:47:31 2012
@@ -131,7 +131,7 @@
UsedAsTypeAttr(false), IsAvailability(false),
NextInPosition(0), NextInPool(0) {
if (numArgs) memcpy(getArgsBuffer(), args, numArgs * sizeof(Expr*));
- AttrKind = getKind(getName());
+ AttrKind = getKind(getName(), getScopeName());
}
AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
@@ -152,7 +152,7 @@
new (&getAvailabilitySlot(IntroducedSlot)) AvailabilityChange(introduced);
new (&getAvailabilitySlot(DeprecatedSlot)) AvailabilityChange(deprecated);
new (&getAvailabilitySlot(ObsoletedSlot)) AvailabilityChange(obsoleted);
- AttrKind = getKind(getName());
+ AttrKind = getKind(getName(), getScopeName());
}
friend class AttributePool;
@@ -162,17 +162,6 @@
enum Kind {
#define PARSED_ATTR(NAME) AT_##NAME,
#include "clang/Sema/AttrParsedAttrList.inc"
- PARSED_ATTR(address_space)
- PARSED_ATTR(base_check)
- PARSED_ATTR(cf_returns_autoreleased)
- PARSED_ATTR(ext_vector_type)
- PARSED_ATTR(mode)
- PARSED_ATTR(neon_polyvector_type)
- PARSED_ATTR(neon_vector_type)
- PARSED_ATTR(objc_gc)
- PARSED_ATTR(objc_ownership)
- PARSED_ATTR(opencl_image_access)
- PARSED_ATTR(vector_size)
#undef PARSED_ATTR
IgnoredAttribute,
UnknownAttribute
@@ -199,7 +188,7 @@
void setUsedAsTypeAttr() { UsedAsTypeAttr = true; }
Kind getKind() const { return Kind(AttrKind); }
- static Kind getKind(const IdentifierInfo *Name);
+ static Kind getKind(const IdentifierInfo *Name, const IdentifierInfo *Scope);
AttributeList *getNext() const { return NextInPosition; }
void setNext(AttributeList *N) { NextInPosition = N; }
Modified: cfe/branches/tooling/include/clang/Sema/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Sema/DeclSpec.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Sema/DeclSpec.h (original)
+++ cfe/branches/tooling/include/clang/Sema/DeclSpec.h Tue May 8 03:47:31 2012
@@ -1150,10 +1150,6 @@
/// \brief Pointer to the expression in the noexcept-specifier of this
/// function, if it has one.
Expr *NoexceptExpr;
-
- /// \brief Pointer to the cached tokens for an exception-specification
- /// that has not yet been parsed.
- CachedTokens *ExceptionSpecTokens;
};
/// TrailingReturnType - If this isn't null, it's the trailing return type
@@ -1176,8 +1172,6 @@
delete[] ArgInfo;
if (getExceptionSpecType() == EST_Dynamic)
delete[] Exceptions;
- else if (getExceptionSpecType() == EST_Delayed)
- delete ExceptionSpecTokens;
}
/// isKNRPrototype - Return true if this is a K&R style identifier list,
@@ -1353,7 +1347,6 @@
SourceRange *ExceptionRanges,
unsigned NumExceptions,
Expr *NoexceptExpr,
- CachedTokens *ExceptionSpecTokens,
SourceLocation LocalRangeBegin,
SourceLocation LocalRangeEnd,
Declarator &TheDeclarator,
Modified: cfe/branches/tooling/include/clang/Sema/DelayedDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Sema/DelayedDiagnostic.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Sema/DelayedDiagnostic.h (original)
+++ cfe/branches/tooling/include/clang/Sema/DelayedDiagnostic.h Tue May 8 03:47:31 2012
@@ -21,7 +21,7 @@
#ifndef LLVM_CLANG_SEMA_DELAYED_DIAGNOSTIC_H
#define LLVM_CLANG_SEMA_DELAYED_DIAGNOSTIC_H
-#include "clang/AST/DeclCXX.h"
+#include "clang/Sema/Sema.h"
namespace clang {
namespace sema {
@@ -214,7 +214,63 @@
};
};
+/// DelayedDiagnosticPool - A collection of diagnostics which were
+/// delayed.
+class DelayedDiagnosticPool {
+ const DelayedDiagnosticPool *Parent;
+ llvm::SmallVector<DelayedDiagnostic, 4> Diagnostics;
+
+ // Do not implement.
+ DelayedDiagnosticPool(const DelayedDiagnosticPool &other);
+ DelayedDiagnosticPool &operator=(const DelayedDiagnosticPool &other);
+public:
+ DelayedDiagnosticPool(const DelayedDiagnosticPool *parent) : Parent(parent) {}
+ ~DelayedDiagnosticPool() {
+ for (llvm::SmallVectorImpl<DelayedDiagnostic>::iterator
+ i = Diagnostics.begin(), e = Diagnostics.end(); i != e; ++i)
+ i->Destroy();
+ }
+
+ const DelayedDiagnosticPool *getParent() const { return Parent; }
+
+ /// Does this pool, or any of its ancestors, contain any diagnostics?
+ bool empty() const {
+ return (Diagnostics.empty() && (Parent == NULL || Parent->empty()));
+ }
+
+ /// Add a diagnostic to this pool.
+ void add(const DelayedDiagnostic &diag) {
+ Diagnostics.push_back(diag);
+ }
+
+ /// Steal the diagnostics from the given pool.
+ void steal(DelayedDiagnosticPool &pool) {
+ if (pool.Diagnostics.empty()) return;
+
+ if (Diagnostics.empty()) {
+ Diagnostics = llvm_move(pool.Diagnostics);
+ } else {
+ Diagnostics.append(pool.pool_begin(), pool.pool_end());
+ }
+ pool.Diagnostics.clear();
+ }
+
+ typedef llvm::SmallVectorImpl<DelayedDiagnostic>::const_iterator
+ pool_iterator;
+ pool_iterator pool_begin() const { return Diagnostics.begin(); }
+ pool_iterator pool_end() const { return Diagnostics.end(); }
+ bool pool_empty() const { return Diagnostics.empty(); }
+};
+
}
+
+/// Add a diagnostic to the current delay pool.
+inline void Sema::DelayedDiagnostics::add(const sema::DelayedDiagnostic &diag) {
+ assert(shouldDelayDiagnostics() && "trying to delay without pool");
+ CurPool->add(diag);
+}
+
+
}
#endif
Modified: cfe/branches/tooling/include/clang/Sema/Overload.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Sema/Overload.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Sema/Overload.h (original)
+++ cfe/branches/tooling/include/clang/Sema/Overload.h Tue May 8 03:47:31 2012
@@ -659,12 +659,25 @@
/// A structure used to record information about a failed
/// template argument deduction.
struct DeductionFailureInfo {
- // A Sema::TemplateDeductionResult.
- unsigned Result;
+ /// A Sema::TemplateDeductionResult.
+ unsigned Result : 8;
+
+ /// \brief Indicates whether a diagnostic is stored in Diagnostic.
+ unsigned HasDiagnostic : 1;
/// \brief Opaque pointer containing additional data about
/// this deduction failure.
void *Data;
+
+ /// \brief A diagnostic indicating why deduction failed.
+ union {
+ void *Align;
+ char Diagnostic[sizeof(PartialDiagnosticAt)];
+ };
+
+ /// \brief Retrieve the diagnostic which caused this deduction failure,
+ /// if any.
+ PartialDiagnosticAt *getSFINAEDiagnostic();
/// \brief Retrieve the template parameter this deduction failure
/// refers to, if any.
@@ -741,9 +754,12 @@
public:
OverloadCandidateSet(SourceLocation Loc) : Loc(Loc), NumInlineSequences(0){}
~OverloadCandidateSet() {
- for (iterator i = begin(), e = end(); i != e; ++i)
+ for (iterator i = begin(), e = end(); i != e; ++i) {
for (unsigned ii = 0, ie = i->NumConversions; ii != ie; ++ii)
i->Conversions[ii].~ImplicitConversionSequence();
+ if (i->FailureKind == ovl_fail_bad_deduction)
+ i->DeductionFailure.Destroy();
+ }
}
SourceLocation getLocation() const { return Loc; }
Modified: cfe/branches/tooling/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Sema/Sema.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Sema/Sema.h (original)
+++ cfe/branches/tooling/include/clang/Sema/Sema.h Tue May 8 03:47:31 2012
@@ -169,6 +169,7 @@
class BlockScopeInfo;
class CompoundScopeInfo;
class DelayedDiagnostic;
+ class DelayedDiagnosticPool;
class FunctionScopeInfo;
class LambdaScopeInfo;
class PossiblyUnreachableDiag;
@@ -355,93 +356,63 @@
class DelayedDiagnostics;
- class ParsingDeclState {
- unsigned SavedStackSize;
- friend class Sema::DelayedDiagnostics;
- };
-
- class ProcessingContextState {
- unsigned SavedParsingDepth;
- unsigned SavedActiveStackBase;
+ class DelayedDiagnosticsState {
+ sema::DelayedDiagnosticPool *SavedPool;
friend class Sema::DelayedDiagnostics;
};
+ typedef DelayedDiagnosticsState ParsingDeclState;
+ typedef DelayedDiagnosticsState ProcessingContextState;
/// A class which encapsulates the logic for delaying diagnostics
/// during parsing and other processing.
class DelayedDiagnostics {
- /// \brief The stack of diagnostics that were delayed due to being
- /// produced during the parsing of a declaration.
- sema::DelayedDiagnostic *Stack;
-
- /// \brief The number of objects on the delayed-diagnostics stack.
- unsigned StackSize;
-
- /// \brief The current capacity of the delayed-diagnostics stack.
- unsigned StackCapacity;
-
- /// \brief The index of the first "active" delayed diagnostic in
- /// the stack. When parsing class definitions, we ignore active
- /// delayed diagnostics from the surrounding context.
- unsigned ActiveStackBase;
-
- /// \brief The depth of the declarations we're currently parsing.
- /// This gets saved and reset whenever we enter a class definition.
- unsigned ParsingDepth;
+ /// \brief The current pool of diagnostics into which delayed
+ /// diagnostics should go.
+ sema::DelayedDiagnosticPool *CurPool;
public:
- DelayedDiagnostics() : Stack(0), StackSize(0), StackCapacity(0),
- ActiveStackBase(0), ParsingDepth(0) {}
+ DelayedDiagnostics() : CurPool(0) {}
- ~DelayedDiagnostics() {
- delete[] reinterpret_cast<char*>(Stack);
- }
-
- /// Adds a delayed diagnostic.
- void add(const sema::DelayedDiagnostic &diag);
+ /// Adds a delayed diagnostic.
+ void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
/// Determines whether diagnostics should be delayed.
- bool shouldDelayDiagnostics() { return ParsingDepth > 0; }
+ bool shouldDelayDiagnostics() { return CurPool != 0; }
- /// Observe that we've started parsing a declaration. Access and
- /// deprecation diagnostics will be delayed; when the declaration
- /// is completed, all active delayed diagnostics will be evaluated
- /// in its context, and then active diagnostics stack will be
- /// popped down to the saved depth.
- ParsingDeclState pushParsingDecl() {
- ParsingDepth++;
+ /// Returns the current delayed-diagnostics pool.
+ sema::DelayedDiagnosticPool *getCurrentPool() const {
+ return CurPool;
+ }
- ParsingDeclState state;
- state.SavedStackSize = StackSize;
+ /// Enter a new scope. Access and deprecation diagnostics will be
+ /// collected in this pool.
+ DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) {
+ DelayedDiagnosticsState state;
+ state.SavedPool = CurPool;
+ CurPool = &pool;
return state;
}
- /// Observe that we're completed parsing a declaration.
- static void popParsingDecl(Sema &S, ParsingDeclState state, Decl *decl);
-
- /// Observe that we've started processing a different context, the
- /// contents of which are semantically separate from the
- /// declarations it may lexically appear in. This sets aside the
- /// current stack of active diagnostics and starts afresh.
- ProcessingContextState pushContext() {
- assert(StackSize >= ActiveStackBase);
-
- ProcessingContextState state;
- state.SavedParsingDepth = ParsingDepth;
- state.SavedActiveStackBase = ActiveStackBase;
-
- ActiveStackBase = StackSize;
- ParsingDepth = 0;
+ /// Leave a delayed-diagnostic state that was previously pushed.
+ /// Do not emit any of the diagnostics. This is performed as part
+ /// of the bookkeeping of popping a pool "properly".
+ void popWithoutEmitting(DelayedDiagnosticsState state) {
+ CurPool = state.SavedPool;
+ }
+ /// Enter a new scope where access and deprecation diagnostics are
+ /// not delayed.
+ DelayedDiagnosticsState pushUndelayed() {
+ DelayedDiagnosticsState state;
+ state.SavedPool = CurPool;
+ CurPool = 0;
return state;
}
- /// Observe that we've stopped processing a context. This
- /// restores the previous stack of active diagnostics.
- void popContext(ProcessingContextState state) {
- assert(ActiveStackBase == StackSize);
- assert(ParsingDepth == 0);
- ActiveStackBase = state.SavedActiveStackBase;
- ParsingDepth = state.SavedParsingDepth;
+ /// Undo a previous pushUndelayed().
+ void popUndelayed(DelayedDiagnosticsState state) {
+ assert(CurPool == NULL);
+ CurPool = state.SavedPool;
}
} DelayedDiagnostics;
@@ -456,7 +427,7 @@
public:
ContextRAII(Sema &S, DeclContext *ContextToPush)
: S(S), SavedContext(S.CurContext),
- SavedContextState(S.DelayedDiagnostics.pushContext()),
+ SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
{
assert(ContextToPush && "pushing null context");
@@ -466,7 +437,7 @@
void pop() {
if (!SavedContext) return;
S.CurContext = SavedContext;
- S.DelayedDiagnostics.popContext(SavedContextState);
+ S.DelayedDiagnostics.popUndelayed(SavedContextState);
S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
SavedContext = 0;
}
@@ -833,7 +804,8 @@
bool findMacroSpelling(SourceLocation &loc, StringRef name);
/// \brief Get a string to suggest for zero-initialization of a type.
- const char *getFixItZeroInitializerForType(QualType T) const;
+ std::string getFixItZeroInitializerForType(QualType T) const;
+ std::string getFixItZeroLiteralForType(QualType T) const;
ExprResult Owned(Expr* E) { return E; }
ExprResult Owned(ExprResult R) { return R; }
@@ -943,19 +915,168 @@
/// in an Objective-C message declaration. Return the appropriate type.
ParsedType ActOnObjCInstanceType(SourceLocation Loc);
+ /// \brief Abstract class used to diagnose incomplete types.
+ struct TypeDiagnoser {
+ bool Suppressed;
+
+ TypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { }
+
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
+ virtual ~TypeDiagnoser() {}
+ };
+
+ static int getPrintable(int I) { return I; }
+ static unsigned getPrintable(unsigned I) { return I; }
+ static bool getPrintable(bool B) { return B; }
+ static const char * getPrintable(const char *S) { return S; }
+ static StringRef getPrintable(StringRef S) { return S; }
+ static const std::string &getPrintable(const std::string &S) { return S; }
+ static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
+ return II;
+ }
+ static DeclarationName getPrintable(DeclarationName N) { return N; }
+ static QualType getPrintable(QualType T) { return T; }
+ static SourceRange getPrintable(SourceRange R) { return R; }
+ static SourceRange getPrintable(SourceLocation L) { return L; }
+ static SourceRange getPrintable(Expr *E) { return E->getSourceRange(); }
+ static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
+
+ template<typename T1>
+ class BoundTypeDiagnoser1 : public TypeDiagnoser {
+ unsigned DiagID;
+ const T1 &Arg1;
+
+ public:
+ BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1)
+ : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { }
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ if (Suppressed) return;
+ S.Diag(Loc, DiagID) << getPrintable(Arg1) << T;
+ }
+
+ virtual ~BoundTypeDiagnoser1() { }
+ };
+
+ template<typename T1, typename T2>
+ class BoundTypeDiagnoser2 : public TypeDiagnoser {
+ unsigned DiagID;
+ const T1 &Arg1;
+ const T2 &Arg2;
+
+ public:
+ BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1,
+ const T2 &Arg2)
+ : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
+ Arg2(Arg2) { }
+
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ if (Suppressed) return;
+ S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T;
+ }
+
+ virtual ~BoundTypeDiagnoser2() { }
+ };
+
+ template<typename T1, typename T2, typename T3>
+ class BoundTypeDiagnoser3 : public TypeDiagnoser {
+ unsigned DiagID;
+ const T1 &Arg1;
+ const T2 &Arg2;
+ const T3 &Arg3;
+
+ public:
+ BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1,
+ const T2 &Arg2, const T3 &Arg3)
+ : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
+ Arg2(Arg2), Arg3(Arg3) { }
+
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ if (Suppressed) return;
+ S.Diag(Loc, DiagID)
+ << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T;
+ }
+
+ virtual ~BoundTypeDiagnoser3() { }
+ };
+
bool RequireCompleteType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD,
- std::pair<SourceLocation, PartialDiagnostic> Note);
- bool RequireCompleteType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD);
+ TypeDiagnoser &Diagnoser);
bool RequireCompleteType(SourceLocation Loc, QualType T,
unsigned DiagID);
- bool RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD,
- std::pair<SourceLocation,
- PartialDiagnostic> Note);
+
+ template<typename T1>
+ bool RequireCompleteType(SourceLocation Loc, QualType T,
+ unsigned DiagID, const T1 &Arg1) {
+ BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
+ return RequireCompleteType(Loc, T, Diagnoser);
+ }
+
+ template<typename T1, typename T2>
+ bool RequireCompleteType(SourceLocation Loc, QualType T,
+ unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
+ BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
+ return RequireCompleteType(Loc, T, Diagnoser);
+ }
+
+ template<typename T1, typename T2, typename T3>
+ bool RequireCompleteType(SourceLocation Loc, QualType T,
+ unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
+ const T3 &Arg3) {
+ BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
+ Arg3);
+ return RequireCompleteType(Loc, T, Diagnoser);
+ }
+
+ bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
+ bool RequireCompleteExprType(Expr *E, unsigned DiagID);
+
+ template<typename T1>
+ bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) {
+ BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
+ return RequireCompleteExprType(E, Diagnoser);
+ }
+
+ template<typename T1, typename T2>
+ bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
+ const T2 &Arg2) {
+ BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
+ return RequireCompleteExprType(E, Diagnoser);
+ }
+
+ template<typename T1, typename T2, typename T3>
+ bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
+ const T2 &Arg2, const T3 &Arg3) {
+ BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
+ Arg3);
+ return RequireCompleteExprType(E, Diagnoser);
+ }
+
+ bool RequireLiteralType(SourceLocation Loc, QualType T,
+ TypeDiagnoser &Diagnoser);
+ bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
+
+ template<typename T1>
+ bool RequireLiteralType(SourceLocation Loc, QualType T,
+ unsigned DiagID, const T1 &Arg1) {
+ BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
+ return RequireLiteralType(Loc, T, Diagnoser);
+ }
+
+ template<typename T1, typename T2>
+ bool RequireLiteralType(SourceLocation Loc, QualType T,
+ unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
+ BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
+ return RequireLiteralType(Loc, T, Diagnoser);
+ }
+ template<typename T1, typename T2, typename T3>
bool RequireLiteralType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD);
+ unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
+ const T3 &Arg3) {
+ BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
+ Arg3);
+ return RequireLiteralType(Loc, T, Diagnoser);
+ }
QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
const CXXScopeSpec &SS, QualType T);
@@ -1565,16 +1686,59 @@
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
llvm::APSInt &Value, CCEKind CCE);
+ /// \brief Abstract base class used to diagnose problems that occur while
+ /// trying to convert an expression to integral or enumeration type.
+ class ICEConvertDiagnoser {
+ public:
+ bool Suppress;
+ bool SuppressConversion;
+
+ ICEConvertDiagnoser(bool Suppress = false,
+ bool SuppressConversion = false)
+ : Suppress(Suppress), SuppressConversion(SuppressConversion) { }
+
+ /// \brief Emits a diagnostic complaining that the expression does not have
+ /// integral or enumeration type.
+ virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
+ QualType T) = 0;
+
+ /// \brief Emits a diagnostic when the expression has incomplete class type.
+ virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc,
+ QualType T) = 0;
+
+ /// \brief Emits a diagnostic when the only matching conversion function
+ /// is explicit.
+ virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) = 0;
+
+ /// \brief Emits a note for the explicit conversion function.
+ virtual DiagnosticBuilder
+ noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
+
+ /// \brief Emits a diagnostic when there are multiple possible conversion
+ /// functions.
+ virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
+ QualType T) = 0;
+
+ /// \brief Emits a note for one of the candidate conversions.
+ virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv,
+ QualType ConvTy) = 0;
+
+ /// \brief Emits a diagnostic when we picked a conversion function
+ /// (for cases when we are not allowed to pick a conversion function).
+ virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) = 0;
+
+ virtual ~ICEConvertDiagnoser() {}
+ };
+
ExprResult
ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
- const PartialDiagnostic &NotIntDiag,
- const PartialDiagnostic &IncompleteDiag,
- const PartialDiagnostic &ExplicitConvDiag,
- const PartialDiagnostic &ExplicitConvNote,
- const PartialDiagnostic &AmbigDiag,
- const PartialDiagnostic &AmbigNote,
- const PartialDiagnostic &ConvDiag,
+ ICEConvertDiagnoser &Diagnoser,
bool AllowScopedEnumerations);
+
enum ObjCSubscriptKind {
OS_Array,
OS_Dictionary,
@@ -2415,21 +2579,21 @@
void DiagnoseEmptyLoopBody(const Stmt *S,
const Stmt *PossibleBody);
- ParsingDeclState PushParsingDeclaration() {
- return DelayedDiagnostics.pushParsingDecl();
- }
- void PopParsingDeclaration(ParsingDeclState state, Decl *decl) {
- DelayedDiagnostics::popParsingDecl(*this, state, decl);
+ ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) {
+ return DelayedDiagnostics.push(pool);
}
+ void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
typedef ProcessingContextState ParsingClassState;
ParsingClassState PushParsingClass() {
- return DelayedDiagnostics.pushContext();
+ return DelayedDiagnostics.pushUndelayed();
}
void PopParsingClass(ParsingClassState state) {
- DelayedDiagnostics.popContext(state);
+ DelayedDiagnostics.popUndelayed(state);
}
+ void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
+
void EmitDeprecationWarning(NamedDecl *D, StringRef Message,
SourceLocation Loc,
const ObjCInterfaceDecl *UnknownObjCClass=0);
@@ -3174,16 +3338,6 @@
llvm::SmallVectorImpl<QualType> &Exceptions,
FunctionProtoType::ExtProtoInfo &EPI);
- /// \brief Add an exception-specification to the given member function
- /// (or member function template). The exception-specification was parsed
- /// after the method itself was declared.
- void actOnDelayedExceptionSpecification(Decl *Method,
- ExceptionSpecificationType EST,
- SourceRange SpecificationRange,
- ArrayRef<ParsedType> DynamicExceptions,
- ArrayRef<SourceRange> DynamicExceptionRanges,
- Expr *NoexceptExpr);
-
/// \brief Determine if a special member function should have a deleted
/// definition when it is defaulted.
bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
@@ -4243,36 +4397,10 @@
void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
- /// A flag to suppress access checking.
- bool SuppressAccessChecking;
-
/// \brief When true, access checking violations are treated as SFINAE
/// failures rather than hard errors.
bool AccessCheckingSFINAE;
- /// \brief RAII object used to temporarily suppress access checking.
- class SuppressAccessChecksRAII {
- Sema &S;
- bool SuppressingAccess;
-
- public:
- SuppressAccessChecksRAII(Sema &S, bool Suppress)
- : S(S), SuppressingAccess(Suppress) {
- if (Suppress) S.ActOnStartSuppressingAccessChecks();
- }
- ~SuppressAccessChecksRAII() {
- done();
- }
- void done() {
- if (!SuppressingAccess) return;
- S.ActOnStopSuppressingAccessChecks();
- SuppressingAccess = false;
- }
- };
-
- void ActOnStartSuppressingAccessChecks();
- void ActOnStopSuppressingAccessChecks();
-
enum AbstractDiagSelID {
AbstractNone = -1,
AbstractReturnType,
@@ -4283,7 +4411,31 @@
};
bool RequireNonAbstractType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD);
+ TypeDiagnoser &Diagnoser);
+ template<typename T1>
+ bool RequireNonAbstractType(SourceLocation Loc, QualType T,
+ unsigned DiagID,
+ const T1 &Arg1) {
+ BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
+ return RequireNonAbstractType(Loc, T, Diagnoser);
+ }
+
+ template<typename T1, typename T2>
+ bool RequireNonAbstractType(SourceLocation Loc, QualType T,
+ unsigned DiagID,
+ const T1 &Arg1, const T2 &Arg2) {
+ BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
+ return RequireNonAbstractType(Loc, T, Diagnoser);
+ }
+
+ template<typename T1, typename T2, typename T3>
+ bool RequireNonAbstractType(SourceLocation Loc, QualType T,
+ unsigned DiagID,
+ const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) {
+ BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3);
+ return RequireNonAbstractType(Loc, T, Diagnoser);
+ }
+
void DiagnoseAbstractType(const CXXRecordDecl *RD);
bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
@@ -5824,9 +5976,6 @@
const IdentifierInfo *Name);
void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
- void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
- ObjCMethodDecl *MethodDecl,
- bool IsInstance);
void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
@@ -6577,20 +6726,29 @@
/// in the global scope.
bool CheckObjCDeclScope(Decl *D);
+ /// \brief Abstract base class used for diagnosing integer constant
+ /// expression violations.
+ class VerifyICEDiagnoser {
+ public:
+ bool Suppress;
+
+ VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { }
+
+ virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0;
+ virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR);
+ virtual ~VerifyICEDiagnoser() { }
+ };
+
/// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
/// and reports the appropriate diagnostics. Returns false on success.
/// Can optionally return the value of the expression.
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
- const PartialDiagnostic &Diag,
- bool AllowFold,
- const PartialDiagnostic &FoldDiag);
+ VerifyICEDiagnoser &Diagnoser,
+ bool AllowFold = true);
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
- const PartialDiagnostic &Diag,
- bool AllowFold = true) {
- return VerifyIntegerConstantExpression(E, Result, Diag, AllowFold,
- PDiag(0));
- }
- ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result = 0);
+ unsigned DiagID,
+ bool AllowFold = true);
+ ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result=0);
/// VerifyBitField - verifies that a bit field expression is an ICE and has
/// the correct width, and that the field type is valid.
Modified: cfe/branches/tooling/include/clang/Sema/TemplateDeduction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Sema/TemplateDeduction.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Sema/TemplateDeduction.h (original)
+++ cfe/branches/tooling/include/clang/Sema/TemplateDeduction.h Tue May 8 03:47:31 2012
@@ -39,6 +39,9 @@
/// deduction is occurring.
SourceLocation Loc;
+ /// \brief Have we suppressed an error during deduction?
+ bool HasSFINAEDiagnostic;
+
/// \brief Warnings (and follow-on notes) that were suppressed due to
/// SFINAE while performing template argument deduction.
SmallVector<PartialDiagnosticAt, 4> SuppressedDiagnostics;
@@ -49,7 +52,7 @@
public:
TemplateDeductionInfo(ASTContext &Context, SourceLocation Loc)
- : Context(Context), Deduced(0), Loc(Loc) { }
+ : Context(Context), Deduced(0), Loc(Loc), HasSFINAEDiagnostic(false) { }
~TemplateDeductionInfo() {
// FIXME: if (Deduced) Deduced->Destroy(Context);
@@ -68,6 +71,15 @@
return Result;
}
+ /// \brief Take ownership of the SFINAE diagnostic.
+ void takeSFINAEDiagnostic(PartialDiagnosticAt &PD) {
+ assert(HasSFINAEDiagnostic);
+ PD.first = SuppressedDiagnostics.front().first;
+ PD.second.swap(SuppressedDiagnostics.front().second);
+ SuppressedDiagnostics.clear();
+ HasSFINAEDiagnostic = false;
+ }
+
/// \brief Provide a new template argument list that contains the
/// results of template argument deduction.
void reset(TemplateArgumentList *NewDeduced) {
@@ -75,10 +87,31 @@
Deduced = NewDeduced;
}
+ /// \brief Is a SFINAE diagnostic available?
+ bool hasSFINAEDiagnostic() const {
+ return HasSFINAEDiagnostic;
+ }
+
+ /// \brief Set the diagnostic which caused the SFINAE failure.
+ void addSFINAEDiagnostic(SourceLocation Loc, PartialDiagnostic PD) {
+ // Only collect the first diagnostic.
+ if (HasSFINAEDiagnostic)
+ return;
+ SuppressedDiagnostics.clear();
+ SuppressedDiagnostics.push_back(
+ std::make_pair(Loc, PartialDiagnostic::NullDiagnostic()));
+ SuppressedDiagnostics.back().second.swap(PD);
+ HasSFINAEDiagnostic = true;
+ }
+
/// \brief Add a new diagnostic to the set of diagnostics
void addSuppressedDiagnostic(SourceLocation Loc,
- const PartialDiagnostic &PD) {
- SuppressedDiagnostics.push_back(std::make_pair(Loc, PD));
+ PartialDiagnostic PD) {
+ if (HasSFINAEDiagnostic)
+ return;
+ SuppressedDiagnostics.push_back(
+ std::make_pair(Loc, PartialDiagnostic::NullDiagnostic()));
+ SuppressedDiagnostics.back().second.swap(PD);
}
/// \brief Iterator over the set of suppressed diagnostics.
Modified: cfe/branches/tooling/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Serialization/ASTReader.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Serialization/ASTReader.h (original)
+++ cfe/branches/tooling/include/clang/Serialization/ASTReader.h Tue May 8 03:47:31 2012
@@ -591,11 +591,14 @@
/// indicates how many separate module file load operations have occurred.
unsigned CurrentGeneration;
+ typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
/// \brief Mapping from switch-case IDs in the chain to switch-case statements
///
/// Statements usually don't have IDs, but switch cases need them, so that the
/// switch statement can refer to them.
- std::map<unsigned, SwitchCase *> SwitchCaseStmts;
+ SwitchCaseMapTy SwitchCaseStmts;
+
+ SwitchCaseMapTy *CurrSwitchCaseStmts;
/// \brief The number of stat() calls that hit/missed the stat
/// cache.
Modified: cfe/branches/tooling/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Serialization/ASTWriter.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/branches/tooling/include/clang/Serialization/ASTWriter.h Tue May 8 03:47:31 2012
@@ -337,7 +337,7 @@
SmallVector<Stmt *, 16> *CollectedStmts;
/// \brief Mapping from SwitchCase statements to IDs.
- std::map<SwitchCase *, unsigned> SwitchCaseIDs;
+ llvm::DenseMap<SwitchCase *, unsigned> SwitchCaseIDs;
/// \brief The number of statements written to the AST file.
unsigned NumStatements;
Modified: cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h (original)
+++ cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h Tue May 8 03:47:31 2012
@@ -190,10 +190,6 @@
return AnaCtxMgr.getContext(D);
}
- AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) {
- return AnaCtxMgr.getContext(D, TU);
- }
-
};
} // enAnaCtxMgrspace
Modified: cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h (original)
+++ cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h Tue May 8 03:47:31 2012
@@ -16,6 +16,7 @@
#ifndef LLVM_CLANG_GR_BASICVALUEFACTORY_H
#define LLVM_CLANG_GR_BASICVALUEFACTORY_H
+#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
@@ -86,28 +87,30 @@
const llvm::APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned);
const llvm::APSInt& getValue(uint64_t X, QualType T);
+ /// Returns the type of the APSInt used to store values of the given QualType.
+ APSIntType getAPSIntType(QualType T) const {
+ assert(T->isIntegerType() || Loc::isLocType(T));
+ return APSIntType(Ctx.getTypeSize(T),
+ !T->isSignedIntegerOrEnumerationType());
+ }
+
/// Convert - Create a new persistent APSInt with the same value as 'From'
/// but with the bitwidth and signedness of 'To'.
const llvm::APSInt &Convert(const llvm::APSInt& To,
const llvm::APSInt& From) {
-
- if (To.isUnsigned() == From.isUnsigned() &&
- To.getBitWidth() == From.getBitWidth())
+ APSIntType TargetType(To);
+ if (TargetType == APSIntType(From))
return From;
- return getValue(From.getSExtValue(), To.getBitWidth(), To.isUnsigned());
+ return getValue(TargetType.convert(From));
}
const llvm::APSInt &Convert(QualType T, const llvm::APSInt &From) {
- assert(T->isIntegerType() || Loc::isLocType(T));
- unsigned bitwidth = Ctx.getTypeSize(T);
- bool isUnsigned
- = T->isUnsignedIntegerOrEnumerationType() || Loc::isLocType(T);
-
- if (isUnsigned == From.isUnsigned() && bitwidth == From.getBitWidth())
+ APSIntType TargetType = getAPSIntType(T);
+ if (TargetType == APSIntType(From))
return From;
- return getValue(From.getSExtValue(), bitwidth, isUnsigned);
+ return getValue(TargetType.convert(From));
}
const llvm::APSInt& getIntValue(uint64_t X, bool isUnsigned) {
@@ -116,25 +119,19 @@
}
inline const llvm::APSInt& getMaxValue(const llvm::APSInt &v) {
- return getValue(llvm::APSInt::getMaxValue(v.getBitWidth(), v.isUnsigned()));
+ return getValue(APSIntType(v).getMaxValue());
}
inline const llvm::APSInt& getMinValue(const llvm::APSInt &v) {
- return getValue(llvm::APSInt::getMinValue(v.getBitWidth(), v.isUnsigned()));
+ return getValue(APSIntType(v).getMinValue());
}
inline const llvm::APSInt& getMaxValue(QualType T) {
- assert(T->isIntegerType() || Loc::isLocType(T));
- bool isUnsigned
- = T->isUnsignedIntegerOrEnumerationType() || Loc::isLocType(T);
- return getValue(llvm::APSInt::getMaxValue(Ctx.getTypeSize(T), isUnsigned));
+ return getValue(getAPSIntType(T).getMaxValue());
}
inline const llvm::APSInt& getMinValue(QualType T) {
- assert(T->isIntegerType() || Loc::isLocType(T));
- bool isUnsigned
- = T->isUnsignedIntegerOrEnumerationType() || Loc::isLocType(T);
- return getValue(llvm::APSInt::getMinValue(Ctx.getTypeSize(T), isUnsigned));
+ return getValue(getAPSIntType(T).getMinValue());
}
inline const llvm::APSInt& Add1(const llvm::APSInt& V) {
Modified: cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h (original)
+++ cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h Tue May 8 03:47:31 2012
@@ -14,15 +14,16 @@
#ifndef LLVM_CLANG_GR_FUNCTIONSUMMARY_H
#define LLVM_CLANG_GR_FUNCTIONSUMMARY_H
+#include <deque>
#include "clang/AST/Decl.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/BitVector.h"
namespace clang {
namespace ento {
-typedef llvm::SmallPtrSet<Decl*, 24> SetOfDecls;
-typedef llvm::SmallPtrSet<const Decl*, 24> SetOfConstDecls;
+typedef std::deque<Decl*> SetOfDecls;
+typedef llvm::DenseSet<const Decl*> SetOfConstDecls;
class FunctionSummariesTy {
struct FunctionSummary {
Modified: cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h (original)
+++ cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h Tue May 8 03:47:31 2012
@@ -197,8 +197,9 @@
}
};
-/// \class The region of the static variables within the current CodeTextRegion
+/// \brief The region of the static variables within the current CodeTextRegion
/// scope.
+///
/// Currently, only the static locals are placed there, so we know that these
/// variables do not get invalidated by calls to other functions.
class StaticGlobalSpaceRegion : public GlobalsSpaceRegion {
@@ -221,7 +222,7 @@
}
};
-/// \class The region for all the non-static global variables.
+/// \brief The region for all the non-static global variables.
///
/// This class is further split into subclasses for efficient implementation of
/// invalidating a set of related global values as is done in
@@ -245,7 +246,7 @@
}
};
-/// \class The region containing globals which are defined in system/external
+/// \brief The region containing globals which are defined in system/external
/// headers and are considered modifiable by system calls (ex: errno).
class GlobalSystemSpaceRegion : public NonStaticGlobalSpaceRegion {
friend class MemRegionManager;
@@ -262,7 +263,7 @@
}
};
-/// \class The region containing globals which are considered not to be modified
+/// \brief The region containing globals which are considered not to be modified
/// or point to data which could be modified as a result of a function call
/// (system or internal). Ex: Const global scalars would be modeled as part of
/// this region. This region also includes most system globals since they have
@@ -282,7 +283,7 @@
}
};
-/// \class The region containing globals which can be modified by calls to
+/// \brief The region containing globals which can be modified by calls to
/// "internally" defined functions - (for now just) functions other then system
/// calls.
class GlobalInternalSpaceRegion : public NonStaticGlobalSpaceRegion {
@@ -579,25 +580,37 @@
const BlockTextRegion *BC;
const LocationContext *LC; // Can be null */
void *ReferencedVars;
+ void *OriginalVars;
BlockDataRegion(const BlockTextRegion *bc, const LocationContext *lc,
const MemRegion *sreg)
- : SubRegion(sreg, BlockDataRegionKind), BC(bc), LC(lc), ReferencedVars(0) {}
+ : SubRegion(sreg, BlockDataRegionKind), BC(bc), LC(lc),
+ ReferencedVars(0), OriginalVars(0) {}
-public:
+public:
const BlockTextRegion *getCodeRegion() const { return BC; }
const BlockDecl *getDecl() const { return BC->getDecl(); }
class referenced_vars_iterator {
const MemRegion * const *R;
+ const MemRegion * const *OriginalR;
public:
- explicit referenced_vars_iterator(const MemRegion * const *r) : R(r) {}
+ explicit referenced_vars_iterator(const MemRegion * const *r,
+ const MemRegion * const *originalR)
+ : R(r), OriginalR(originalR) {}
operator const MemRegion * const *() const {
return R;
}
-
+
+ const MemRegion *getCapturedRegion() const {
+ return *R;
+ }
+ const MemRegion *getOriginalRegion() const {
+ return *OriginalR;
+ }
+
const VarRegion* operator*() const {
return cast<VarRegion>(*R);
}
@@ -610,6 +623,7 @@
}
referenced_vars_iterator &operator++() {
++R;
+ ++OriginalR;
return *this;
}
};
Modified: cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/ObjCMessage.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/ObjCMessage.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/ObjCMessage.h (original)
+++ cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/ObjCMessage.h Tue May 8 03:47:31 2012
@@ -164,6 +164,9 @@
ObjCMessage Msg;
ProgramStateRef State;
const LocationContext *LCtx;
+
+ bool isCallbackArg(unsigned Idx, const Type *T) const;
+
public:
CallOrObjCMessage(const CallExpr *callE, ProgramStateRef state,
const LocationContext *lctx)
@@ -258,6 +261,10 @@
return Msg.getReceiverSourceRange();
}
+ /// \brief Check if one of the arguments might be a callback.
+ bool hasNonZeroCallbackArg() const;
+
+
/// \brief Check if the name corresponds to a CoreFoundation or CoreGraphics
/// function that allows objects to escape.
///
@@ -273,18 +280,7 @@
//
// TODO: To reduce false negatives here, we should track the container
// allocation site and check if a proper deallocator was set there.
- static bool isCFCGAllowingEscape(StringRef FName) {
- if (FName[0] == 'C' && (FName[1] == 'F' || FName[1] == 'G'))
- if (StrInStrNoCase(FName, "InsertValue") != StringRef::npos||
- StrInStrNoCase(FName, "AddValue") != StringRef::npos ||
- StrInStrNoCase(FName, "SetValue") != StringRef::npos ||
- StrInStrNoCase(FName, "WithData") != StringRef::npos ||
- StrInStrNoCase(FName, "AppendValue") != StringRef::npos||
- StrInStrNoCase(FName, "SetAttribute") != StringRef::npos) {
- return true;
- }
- return false;
- }
+ static bool isCFCGAllowingEscape(StringRef FName);
};
}
Modified: cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h (original)
+++ cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h Tue May 8 03:47:31 2012
@@ -107,12 +107,9 @@
/// that value is returned. Otherwise, returns NULL.
virtual const llvm::APSInt *getKnownValue(ProgramStateRef state, SVal val) = 0;
- /// Handles generation of the value in case the builder is not smart enough to
- /// handle the given binary expression. Depending on the state, decides to
- /// either keep the expression or forget the history and generate an
- /// UnknownVal.
- SVal makeGenericVal(ProgramStateRef state, BinaryOperator::Opcode op,
- NonLoc lhs, NonLoc rhs, QualType resultTy);
+ /// Constructs a symbolic expression for two non-location values.
+ SVal makeSymExprValNN(ProgramStateRef state, BinaryOperator::Opcode op,
+ NonLoc lhs, NonLoc rhs, QualType resultTy);
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
SVal lhs, SVal rhs, QualType type);
Modified: cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h (original)
+++ cfe/branches/tooling/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h Tue May 8 03:47:31 2012
@@ -94,6 +94,8 @@
return symbol_iterator(this);
}
static symbol_iterator symbol_end() { return symbol_iterator(); }
+
+ unsigned computeComplexity() const;
};
typedef const SymExpr* SymbolRef;
@@ -553,7 +555,7 @@
BasicValueFactory &getBasicVals() { return BV; }
};
-/// \class A class responsible for cleaning up unused symbols.
+/// \brief A class responsible for cleaning up unused symbols.
class SymbolReaper {
enum SymbolStatus {
NotProcessed,
Modified: cfe/branches/tooling/include/clang/Tooling/Tooling.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Tooling/Tooling.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Tooling/Tooling.h (original)
+++ cfe/branches/tooling/include/clang/Tooling/Tooling.h Tue May 8 03:47:31 2012
@@ -35,6 +35,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LLVM.h"
#include "clang/Driver/Util.h"
+#include "clang/Tooling/CompilationDatabase.h"
#include <string>
#include <vector>
@@ -50,8 +51,6 @@
namespace tooling {
-class CompilationDatabase;
-
/// \brief Interface to generate clang::FrontendActions.
class FrontendActionFactory {
public:
@@ -169,9 +168,8 @@
FileManager &getFiles() { return Files; }
private:
- // We store command lines as pair (file name, command line).
- typedef std::pair< std::string, std::vector<std::string> > CommandLine;
- std::vector<CommandLine> CommandLines;
+ // We store compile commands as pair (file name, compile command).
+ std::vector< std::pair<std::string, CompileCommand> > CompileCommands;
FileManager Files;
// Contains a list of pairs (<file name>, <file content>).
Modified: cfe/branches/tooling/lib/ARCMigrate/FileRemapper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ARCMigrate/FileRemapper.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ARCMigrate/FileRemapper.cpp (original)
+++ cfe/branches/tooling/lib/ARCMigrate/FileRemapper.cpp Tue May 8 03:47:31 2012
@@ -77,7 +77,9 @@
for (unsigned idx = 0; idx+3 <= lines.size(); idx += 3) {
StringRef fromFilename = lines[idx];
unsigned long long timeModified;
- lines[idx+1].getAsInteger(10, timeModified);
+ if (lines[idx+1].getAsInteger(10, timeModified))
+ return report("Invalid file data: '" + lines[idx+1] + "' not a number",
+ Diag);
StringRef toFilename = lines[idx+2];
const FileEntry *origFE = FileMgr->getFile(fromFilename);
Modified: cfe/branches/tooling/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp (original)
+++ cfe/branches/tooling/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp Tue May 8 03:47:31 2012
@@ -210,8 +210,8 @@
ObjCMethodDecl *DeallocM = 0;
ObjCMethodDecl *FinalizeM = 0;
for (ObjCImplementationDecl::instmeth_iterator
- MI = (*I)->instmeth_begin(),
- ME = (*I)->instmeth_end(); MI != ME; ++MI) {
+ MI = I->instmeth_begin(),
+ ME = I->instmeth_end(); MI != ME; ++MI) {
ObjCMethodDecl *MD = *MI;
if (!MD->hasBody())
continue;
Modified: cfe/branches/tooling/lib/ARCMigrate/TransGCAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ARCMigrate/TransGCAttrs.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ARCMigrate/TransGCAttrs.cpp (original)
+++ cfe/branches/tooling/lib/ARCMigrate/TransGCAttrs.cpp Tue May 8 03:47:31 2012
@@ -136,7 +136,7 @@
if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
for (CXXRecordDecl::method_iterator
MI = RD->method_begin(), ME = RD->method_end(); MI != ME; ++MI) {
- if ((*MI)->isOutOfLine())
+ if (MI->isOutOfLine())
return true;
}
return false;
@@ -166,7 +166,7 @@
for (Decl::redecl_iterator
I = D->redecls_begin(), E = D->redecls_end(); I != E; ++I)
- if (!isInMainFile((*I)->getLocation()))
+ if (!isInMainFile(I->getLocation()))
return false;
return true;
Modified: cfe/branches/tooling/lib/ARCMigrate/TransProperties.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ARCMigrate/TransProperties.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ARCMigrate/TransProperties.cpp (original)
+++ cfe/branches/tooling/lib/ARCMigrate/TransProperties.cpp Tue May 8 03:47:31 2012
@@ -85,7 +85,7 @@
if (PrevAtProps->find(RawLoc) != PrevAtProps->end())
continue;
PropsTy &props = AtProps[RawLoc];
- props.push_back(*propI);
+ props.push_back(&*propI);
}
}
@@ -102,7 +102,7 @@
for (prop_impl_iterator
I = prop_impl_iterator(D->decls_begin()),
E = prop_impl_iterator(D->decls_end()); I != E; ++I) {
- ObjCPropertyImplDecl *implD = *I;
+ ObjCPropertyImplDecl *implD = &*I;
if (implD->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize)
continue;
ObjCPropertyDecl *propD = implD->getPropertyDecl();
Modified: cfe/branches/tooling/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp (original)
+++ cfe/branches/tooling/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp Tue May 8 03:47:31 2012
@@ -114,7 +114,7 @@
// this class implementation.
for (ObjCImplDecl::propimpl_iterator
I = IMD->propimpl_begin(), EI = IMD->propimpl_end(); I != EI; ++I) {
- ObjCPropertyImplDecl *PID = *I;
+ ObjCPropertyImplDecl *PID = &*I;
if (PID->getPropertyImplementation() ==
ObjCPropertyImplDecl::Synthesize) {
ObjCPropertyDecl *PD = PID->getPropertyDecl();
Modified: cfe/branches/tooling/lib/ARCMigrate/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ARCMigrate/Transforms.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ARCMigrate/Transforms.cpp (original)
+++ cfe/branches/tooling/lib/ARCMigrate/Transforms.cpp Tue May 8 03:47:31 2012
@@ -472,8 +472,8 @@
for (impl_iterator I = impl_iterator(DC->decls_begin()),
E = impl_iterator(DC->decls_end()); I != E; ++I) {
for (ObjCImplementationDecl::instmeth_iterator
- MI = (*I)->instmeth_begin(),
- ME = (*I)->instmeth_end(); MI != ME; ++MI) {
+ MI = I->instmeth_begin(),
+ ME = I->instmeth_end(); MI != ME; ++MI) {
ObjCMethodDecl *MD = *MI;
if (!MD->hasBody())
continue;
Modified: cfe/branches/tooling/lib/AST/APValue.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/APValue.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/APValue.cpp (original)
+++ cfe/branches/tooling/lib/AST/APValue.cpp Tue May 8 03:47:31 2012
@@ -467,9 +467,9 @@
FI != RD->field_end(); ++FI) {
if (!First)
Out << ", ";
- if ((*FI)->isUnnamedBitfield()) continue;
- getStructField((*FI)->getFieldIndex()).
- printPretty(Out, Ctx, (*FI)->getType());
+ if (FI->isUnnamedBitfield()) continue;
+ getStructField(FI->getFieldIndex()).
+ printPretty(Out, Ctx, FI->getType());
First = false;
}
Out << '}';
Modified: cfe/branches/tooling/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/ASTContext.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/ASTContext.cpp (original)
+++ cfe/branches/tooling/lib/AST/ASTContext.cpp Tue May 8 03:47:31 2012
@@ -436,6 +436,8 @@
} else // C99
WCharTy = getFromTargetType(Target.getWCharType());
+ WIntTy = getFromTargetType(Target.getWIntType());
+
if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++
InitBuiltinType(Char16Ty, BuiltinType::Char16);
else // C99
@@ -1187,7 +1189,7 @@
if (!leafClass) {
for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
E = OI->ivar_end(); I != E; ++I)
- Ivars.push_back(*I);
+ Ivars.push_back(&*I);
} else {
ObjCInterfaceDecl *IDecl = const_cast<ObjCInterfaceDecl *>(OI);
for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv;
@@ -4227,7 +4229,7 @@
for (ObjCCategoryImplDecl::propimpl_iterator
i = CID->propimpl_begin(), e = CID->propimpl_end();
i != e; ++i) {
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
if (PID->getPropertyDecl() == PD) {
if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) {
Dynamic = true;
@@ -4241,7 +4243,7 @@
for (ObjCCategoryImplDecl::propimpl_iterator
i = OID->propimpl_begin(), e = OID->propimpl_end();
i != e; ++i) {
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
if (PID->getPropertyDecl() == PD) {
if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) {
Dynamic = true;
@@ -4563,7 +4565,7 @@
// Special case bit-fields.
if (Field->isBitField()) {
getObjCEncodingForTypeImpl(Field->getType(), S, false, true,
- (*Field));
+ &*Field);
} else {
QualType qt = Field->getType();
getLegacyIntegralTypeEncoding(qt);
@@ -4759,7 +4761,7 @@
Field != FieldEnd; ++Field, ++i) {
uint64_t offs = layout.getFieldOffset(i);
FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs),
- std::make_pair(offs, *Field));
+ std::make_pair(offs, &*Field));
}
if (CXXRec && includeVBases) {
@@ -4787,11 +4789,8 @@
std::multimap<uint64_t, NamedDecl *>::iterator
CurLayObj = FieldOrBaseOffsets.begin();
- if ((CurLayObj != FieldOrBaseOffsets.end() && CurLayObj->first != 0) ||
- (CurLayObj == FieldOrBaseOffsets.end() &&
- CXXRec && CXXRec->isDynamicClass())) {
- assert(CXXRec && CXXRec->isDynamicClass() &&
- "Offset 0 was empty but no VTable ?");
+ if (CXXRec && CXXRec->isDynamicClass() &&
+ (CurLayObj == FieldOrBaseOffsets.end() || CurLayObj->first != 0)) {
if (FD) {
S += "\"_vptr$";
std::string recname = CXXRec->getNameAsString();
Modified: cfe/branches/tooling/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/ASTImporter.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/ASTImporter.cpp (original)
+++ cfe/branches/tooling/lib/AST/ASTImporter.cpp Tue May 8 03:47:31 2012
@@ -1017,7 +1017,7 @@
return false;
}
- if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
+ if (!IsStructurallyEquivalent(Context, &*Field1, &*Field2))
return false;
}
@@ -1852,6 +1852,7 @@
ToData.HasPublicFields = FromData.HasPublicFields;
ToData.HasMutableFields = FromData.HasMutableFields;
ToData.HasOnlyCMembers = FromData.HasOnlyCMembers;
+ ToData.HasInClassInitializer = FromData.HasInClassInitializer;
ToData.HasTrivialDefaultConstructor = FromData.HasTrivialDefaultConstructor;
ToData.HasConstexprNonCopyMoveConstructor
= FromData.HasConstexprNonCopyMoveConstructor;
Modified: cfe/branches/tooling/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/Decl.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/Decl.cpp (original)
+++ cfe/branches/tooling/lib/AST/Decl.cpp Tue May 8 03:47:31 2012
@@ -861,9 +861,7 @@
for (unsigned i = 0; i < NumParams; ++i) {
if (i)
OS << ", ";
- std::string Param;
- FD->getParamDecl(i)->getType().getAsStringInternal(Param, P);
- OS << Param;
+ OS << FD->getParamDecl(i)->getType().stream(P);
}
if (FT->isVariadic()) {
@@ -2463,15 +2461,15 @@
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I, ++Index) {
- (*I)->CachedFieldIndex = Index + 1;
+ I->CachedFieldIndex = Index + 1;
if (IsMsStruct) {
// Zero-length bitfields following non-bitfield members are ignored.
- if (getASTContext().ZeroBitfieldFollowsNonBitfield((*I), LastFD)) {
+ if (getASTContext().ZeroBitfieldFollowsNonBitfield(&*I, LastFD)) {
--Index;
continue;
}
- LastFD = (*I);
+ LastFD = &*I;
}
}
Modified: cfe/branches/tooling/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/DeclBase.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/DeclBase.cpp (original)
+++ cfe/branches/tooling/lib/AST/DeclBase.cpp Tue May 8 03:47:31 2012
@@ -1192,11 +1192,6 @@
return I->second.getLookupResult();
}
-DeclContext::lookup_const_result
-DeclContext::lookup(DeclarationName Name) const {
- return const_cast<DeclContext*>(this)->lookup(Name);
-}
-
void DeclContext::localUncachedLookup(DeclarationName Name,
llvm::SmallVectorImpl<NamedDecl *> &Results) {
Results.clear();
Modified: cfe/branches/tooling/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/DeclCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/DeclCXX.cpp (original)
+++ cfe/branches/tooling/lib/AST/DeclCXX.cpp Tue May 8 03:47:31 2012
@@ -43,6 +43,7 @@
Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true),
HasPrivateFields(false), HasProtectedFields(false), HasPublicFields(false),
HasMutableFields(false), HasOnlyCMembers(true),
+ HasInClassInitializer(false),
HasTrivialDefaultConstructor(true),
HasConstexprNonCopyMoveConstructor(false),
DefaultedDefaultConstructorIsConstexpr(true),
@@ -400,7 +401,7 @@
CXXConstructorDecl *CXXRecordDecl::getMoveConstructor() const {
for (ctor_iterator I = ctor_begin(), E = ctor_end(); I != E; ++I)
if (I->isMoveConstructor())
- return *I;
+ return &*I;
return 0;
}
@@ -458,7 +459,7 @@
CXXMethodDecl *CXXRecordDecl::getMoveAssignmentOperator() const {
for (method_iterator I = method_begin(), E = method_end(); I != E; ++I)
if (I->isMoveAssignmentOperator())
- return *I;
+ return &*I;
return 0;
}
@@ -818,17 +819,19 @@
data().HasNonLiteralTypeFieldsOrBases = true;
if (Field->hasInClassInitializer()) {
- // C++0x [class]p5:
+ data().HasInClassInitializer = true;
+
+ // C++11 [class]p5:
// A default constructor is trivial if [...] no non-static data member
// of its class has a brace-or-equal-initializer.
data().HasTrivialDefaultConstructor = false;
- // C++0x [dcl.init.aggr]p1:
+ // C++11 [dcl.init.aggr]p1:
// An aggregate is a [...] class with [...] no
// brace-or-equal-initializers for non-static data members.
data().Aggregate = false;
- // C++0x [class]p10:
+ // C++11 [class]p10:
// A POD struct is [...] a trivial class.
data().PlainOldData = false;
}
@@ -920,7 +923,7 @@
// -- every constructor involved in initializing non-static data
// members [...] shall be a constexpr constructor
if (!Field->hasInClassInitializer() &&
- !FieldRec->hasConstexprDefaultConstructor())
+ !FieldRec->hasConstexprDefaultConstructor() && !isUnion())
// The standard requires any in-class initializer to be a constant
// expression. We consider this to be a defect.
data().DefaultedDefaultConstructorIsConstexpr = false;
@@ -944,7 +947,7 @@
data().DefaultedDefaultConstructorIsConstexpr = false;
data().DefaultedCopyConstructorIsConstexpr = false;
data().DefaultedMoveConstructorIsConstexpr = false;
- } else if (!Field->hasInClassInitializer())
+ } else if (!Field->hasInClassInitializer() && !isUnion())
data().DefaultedDefaultConstructorIsConstexpr = false;
}
@@ -996,11 +999,11 @@
for (LambdaExpr::Capture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures;
C != CEnd; ++C, ++Field) {
if (C->capturesThis()) {
- ThisCapture = *Field;
+ ThisCapture = &*Field;
continue;
}
- Captures[C->getCapturedVar()] = *Field;
+ Captures[C->getCapturedVar()] = &*Field;
}
}
@@ -1050,8 +1053,10 @@
HiddenTypes = &HiddenTypesBuffer;
for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) {
- bool Hidden =
- !HiddenTypesBuffer.insert(GetConversionType(Context, I.getDecl()));
+ CanQualType ConvType(GetConversionType(Context, I.getDecl()));
+ bool Hidden = ParentHiddenTypes.count(ConvType);
+ if (!Hidden)
+ HiddenTypesBuffer.insert(ConvType);
// If this conversion is hidden and we're in a virtual base,
// remember that it's hidden along some inheritance path.
Modified: cfe/branches/tooling/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/DeclObjC.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/DeclObjC.cpp (original)
+++ cfe/branches/tooling/lib/AST/DeclObjC.cpp Tue May 8 03:47:31 2012
@@ -767,9 +767,9 @@
ObjCIvarDecl *curIvar = 0;
if (!ivar_empty()) {
ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
- data().IvarList = (*I); ++I;
- for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
- curIvar->setNextIvar(*I);
+ data().IvarList = &*I; ++I;
+ for (curIvar = data().IvarList; I != E; curIvar = &*I, ++I)
+ curIvar->setNextIvar(&*I);
}
for (const ObjCCategoryDecl *CDecl = getFirstClassExtension(); CDecl;
@@ -778,11 +778,11 @@
ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(),
E = CDecl->ivar_end();
if (!data().IvarList) {
- data().IvarList = (*I); ++I;
+ data().IvarList = &*I; ++I;
curIvar = data().IvarList;
}
- for ( ;I != E; curIvar = *I, ++I)
- curIvar->setNextIvar(*I);
+ for ( ;I != E; curIvar = &*I, ++I)
+ curIvar->setNextIvar(&*I);
}
}
@@ -791,11 +791,11 @@
ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
E = ImplDecl->ivar_end();
if (!data().IvarList) {
- data().IvarList = (*I); ++I;
+ data().IvarList = &*I; ++I;
curIvar = data().IvarList;
}
- for ( ;I != E; curIvar = *I, ++I)
- curIvar->setNextIvar(*I);
+ for ( ;I != E; curIvar = &*I, ++I)
+ curIvar->setNextIvar(&*I);
}
}
return data().IvarList;
@@ -1175,7 +1175,7 @@
ObjCPropertyImplDecl *ObjCImplDecl::
FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
if (PID->getPropertyIvarDecl() &&
PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
return PID;
@@ -1190,7 +1190,7 @@
ObjCPropertyImplDecl *ObjCImplDecl::
FindPropertyImplDecl(IdentifierInfo *Id) const {
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
if (PID->getPropertyDecl()->getIdentifier() == Id)
return PID;
}
Modified: cfe/branches/tooling/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/DeclPrinter.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/DeclPrinter.cpp (original)
+++ cfe/branches/tooling/lib/AST/DeclPrinter.cpp Tue May 8 03:47:31 2012
@@ -322,15 +322,13 @@
}
void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
- std::string S = D->getNameAsString();
- D->getUnderlyingType().getAsStringInternal(S, Policy);
if (!Policy.SuppressSpecifiers) {
Out << "typedef ";
if (D->isModulePrivate())
Out << "__module_private__ ";
}
- Out << S;
+ D->getUnderlyingType().print(Out, Policy, D->getName());
prettyPrintAttributes(D);
}
@@ -350,11 +348,8 @@
}
Out << *D;
- if (D->isFixed()) {
- std::string Underlying;
- D->getIntegerType().getAsStringInternal(Underlying, Policy);
- Out << " : " << Underlying;
- }
+ if (D->isFixed())
+ Out << " : " << D->getIntegerType().stream(Policy);
if (D->isCompleteDefinition()) {
Out << " {\n";
@@ -460,9 +455,7 @@
if (I)
Proto += ", ";
- std::string ExceptionType;
- FT->getExceptionType(I).getAsStringInternal(ExceptionType, SubPolicy);
- Proto += ExceptionType;
+ Proto += FT->getExceptionType(I).getAsString(SubPolicy);;
}
Proto += ")";
} else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
@@ -542,12 +535,11 @@
}
}
else
- AFT->getResultType().getAsStringInternal(Proto, Policy);
+ AFT->getResultType().print(Out, Policy, Proto);
} else {
- Ty.getAsStringInternal(Proto, Policy);
+ Ty.print(Out, Policy, Proto);
}
- Out << Proto;
prettyPrintAttributes(D);
if (D->isPure())
@@ -581,9 +573,7 @@
if (!Policy.SuppressSpecifiers && D->isModulePrivate())
Out << "__module_private__ ";
- std::string Name = D->getNameAsString();
- D->getType().getAsStringInternal(Name, Policy);
- Out << Name;
+ Out << D->getType().stream(Policy, D->getName());
if (D->isBitField()) {
Out << " : ";
@@ -613,12 +603,10 @@
if (!Policy.SuppressSpecifiers && D->isModulePrivate())
Out << "__module_private__ ";
- std::string Name = D->getNameAsString();
QualType T = D->getType();
if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D))
T = Parm->getOriginalType();
- T.getAsStringInternal(Name, Policy);
- Out << Name;
+ T.print(Out, Policy, D->getName());
Expr *Init = D->getInit();
if (!Policy.SuppressInitializers && Init) {
bool ImplicitInit = false;
@@ -666,6 +654,8 @@
// C++ declarations
//----------------------------------------------------------------------------
void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
+ if (D->isInline())
+ Out << "inline ";
Out << "namespace " << *D << " {\n";
VisitDeclContext(D);
Indent() << "}";
@@ -923,7 +913,7 @@
Indentation += Policy.Indentation;
for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
E = OID->ivar_end(); I != E; ++I) {
- Indent() << (*I)->getType().getAsString(Policy) << ' ' << **I << ";\n";
+ Indent() << I->getType().getAsString(Policy) << ' ' << *I << ";\n";
}
Indentation -= Policy.Indentation;
Out << "}\n";
Modified: cfe/branches/tooling/lib/AST/DeclTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/DeclTemplate.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/DeclTemplate.cpp (original)
+++ cfe/branches/tooling/lib/AST/DeclTemplate.cpp Tue May 8 03:47:31 2012
@@ -145,7 +145,7 @@
template <class EntryType>
typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
RedeclarableTemplateDecl::findSpecializationImpl(
- llvm::FoldingSet<EntryType> &Specs,
+ llvm::FoldingSetVector<EntryType> &Specs,
const TemplateArgument *Args, unsigned NumArgs,
void *&InsertPos) {
typedef SpecEntryTraits<EntryType> SETraits;
@@ -298,13 +298,13 @@
}
}
-llvm::FoldingSet<ClassTemplateSpecializationDecl> &
+llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
ClassTemplateDecl::getSpecializations() {
LoadLazySpecializations();
return getCommonPtr()->Specializations;
}
-llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &
+llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
ClassTemplateDecl::getPartialSpecializations() {
LoadLazySpecializations();
return getCommonPtr()->PartialSpecializations;
@@ -363,11 +363,11 @@
void ClassTemplateDecl::getPartialSpecializations(
SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
- llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &PartialSpecs
+ llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
= getPartialSpecializations();
PS.clear();
PS.resize(PartialSpecs.size());
- for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
+ for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
P != PEnd; ++P) {
assert(!PS[P->getSequenceNumber()]);
@@ -378,7 +378,8 @@
ClassTemplatePartialSpecializationDecl *
ClassTemplateDecl::findPartialSpecialization(QualType T) {
ASTContext &Context = getASTContext();
- typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
+ using llvm::FoldingSetVector;
+ typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
partial_spec_iterator;
for (partial_spec_iterator P = getPartialSpecializations().begin(),
PEnd = getPartialSpecializations().end();
@@ -394,7 +395,7 @@
ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
ClassTemplatePartialSpecializationDecl *D) {
Decl *DCanon = D->getCanonicalDecl();
- for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
+ for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
P = getPartialSpecializations().begin(),
PEnd = getPartialSpecializations().end();
P != PEnd; ++P) {
Modified: cfe/branches/tooling/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/DeclarationName.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/DeclarationName.cpp (original)
+++ cfe/branches/tooling/lib/AST/DeclarationName.cpp Tue May 8 03:47:31 2012
@@ -135,33 +135,6 @@
} // end namespace clang
-DeclarationName::DeclarationName(Selector Sel) {
- if (!Sel.getAsOpaquePtr()) {
- Ptr = 0;
- return;
- }
-
- switch (Sel.getNumArgs()) {
- case 0:
- Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
- assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
- Ptr |= StoredObjCZeroArgSelector;
- break;
-
- case 1:
- Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
- assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
- Ptr |= StoredObjCOneArgSelector;
- break;
-
- default:
- Ptr = Sel.InfoPtr & ~Selector::ArgFlags;
- assert((Ptr & PtrMask) == 0 && "Improperly aligned MultiKeywordSelector");
- Ptr |= StoredDeclarationNameExtra;
- break;
- }
-}
-
DeclarationName::NameKind DeclarationName::getNameKind() const {
switch (getStoredNameKind()) {
case StoredIdentifier: return Identifier;
@@ -305,28 +278,10 @@
return 0;
}
-Selector DeclarationName::getObjCSelector() const {
- switch (getNameKind()) {
- case ObjCZeroArgSelector:
- return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 0);
-
- case ObjCOneArgSelector:
- return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 1);
-
- case ObjCMultiArgSelector:
- return Selector(reinterpret_cast<MultiKeywordSelector *>(Ptr & ~PtrMask));
-
- default:
- break;
- }
-
- return Selector();
-}
-
-void *DeclarationName::getFETokenInfoAsVoid() const {
+void *DeclarationName::getFETokenInfoAsVoidSlow() const {
switch (getNameKind()) {
case Identifier:
- return getAsIdentifierInfo()->getFETokenInfo<void>();
+ llvm_unreachable("Handled by getFETokenInfoAsVoid()");
case CXXConstructorName:
case CXXDestructorName:
@@ -481,12 +436,6 @@
return DeclarationName(LiteralName);
}
-unsigned
-llvm::DenseMapInfo<clang::DeclarationName>::
-getHashValue(clang::DeclarationName N) {
- return DenseMapInfo<void*>::getHashValue(N.getAsOpaquePtr());
-}
-
DeclarationNameLoc::DeclarationNameLoc(DeclarationName Name) {
switch (Name.getNameKind()) {
case DeclarationName::Identifier:
Modified: cfe/branches/tooling/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/Expr.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/Expr.cpp (original)
+++ cfe/branches/tooling/lib/AST/Expr.cpp Tue May 8 03:47:31 2012
@@ -414,9 +414,7 @@
if (FT) {
for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) {
if (i) POut << ", ";
- std::string Param;
- Decl->getParamDecl(i)->getType().getAsStringInternal(Param, Policy);
- POut << Param;
+ POut << Decl->getParamDecl(i)->getType().stream(Policy);
}
if (FT->isVariadic()) {
Modified: cfe/branches/tooling/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/ExprCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/ExprCXX.cpp (original)
+++ cfe/branches/tooling/lib/AST/ExprCXX.cpp Tue May 8 03:47:31 2012
@@ -415,30 +415,27 @@
return SourceRange(Loc, End);
}
-SourceRange CXXOperatorCallExpr::getSourceRange() const {
+SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
OverloadedOperatorKind Kind = getOperator();
if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
if (getNumArgs() == 1)
// Prefix operator
- return SourceRange(getOperatorLoc(),
- getArg(0)->getSourceRange().getEnd());
+ return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
else
// Postfix operator
- return SourceRange(getArg(0)->getSourceRange().getBegin(),
- getOperatorLoc());
+ return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
} else if (Kind == OO_Arrow) {
return getArg(0)->getSourceRange();
} else if (Kind == OO_Call) {
- return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
+ return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
} else if (Kind == OO_Subscript) {
- return SourceRange(getArg(0)->getSourceRange().getBegin(), getRParenLoc());
+ return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
} else if (getNumArgs() == 1) {
- return SourceRange(getOperatorLoc(), getArg(0)->getSourceRange().getEnd());
+ return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
} else if (getNumArgs() == 2) {
- return SourceRange(getArg(0)->getSourceRange().getBegin(),
- getArg(1)->getSourceRange().getEnd());
+ return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
} else {
- return SourceRange();
+ return getOperatorLoc();
}
}
@@ -461,7 +458,7 @@
}
-CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() {
+CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Expr* ThisArg = getImplicitObjectArgument();
if (!ThisArg)
return 0;
Modified: cfe/branches/tooling/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/ExprConstant.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/ExprConstant.cpp (original)
+++ cfe/branches/tooling/lib/AST/ExprConstant.cpp Tue May 8 03:47:31 2012
@@ -1072,8 +1072,8 @@
}
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I) {
- if (!CheckConstantExpression(Info, DiagLoc, (*I)->getType(),
- Value.getStructField((*I)->getFieldIndex())))
+ if (!CheckConstantExpression(Info, DiagLoc, I->getType(),
+ Value.getStructField(I->getFieldIndex())))
return false;
}
}
@@ -1282,6 +1282,7 @@
// Truncate the path to the subobject, and remove any derived-to-base offsets.
const RecordDecl *RD = TruncatedType;
for (unsigned I = TruncatedElements, N = D.Entries.size(); I != N; ++I) {
+ if (RD->isInvalidDecl()) return false;
const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD);
const CXXRecordDecl *Base = getAsBaseClass(D.Entries[I]);
if (isVirtualBaseClass(D.Entries[I]))
@@ -1294,13 +1295,18 @@
return true;
}
-static void HandleLValueDirectBase(EvalInfo &Info, const Expr *E, LValue &Obj,
+static bool HandleLValueDirectBase(EvalInfo &Info, const Expr *E, LValue &Obj,
const CXXRecordDecl *Derived,
const CXXRecordDecl *Base,
const ASTRecordLayout *RL = 0) {
- if (!RL) RL = &Info.Ctx.getASTRecordLayout(Derived);
+ if (!RL) {
+ if (Derived->isInvalidDecl()) return false;
+ RL = &Info.Ctx.getASTRecordLayout(Derived);
+ }
+
Obj.getLValueOffset() += RL->getBaseClassOffset(Base);
Obj.addDecl(Info, E, Base, /*Virtual*/ false);
+ return true;
}
static bool HandleLValueBase(EvalInfo &Info, const Expr *E, LValue &Obj,
@@ -1308,10 +1314,8 @@
const CXXBaseSpecifier *Base) {
const CXXRecordDecl *BaseDecl = Base->getType()->getAsCXXRecordDecl();
- if (!Base->isVirtual()) {
- HandleLValueDirectBase(Info, E, Obj, DerivedDecl, BaseDecl);
- return true;
- }
+ if (!Base->isVirtual())
+ return HandleLValueDirectBase(Info, E, Obj, DerivedDecl, BaseDecl);
SubobjectDesignator &D = Obj.Designator;
if (D.Invalid)
@@ -1323,6 +1327,7 @@
return false;
// Find the virtual base class.
+ if (DerivedDecl->isInvalidDecl()) return false;
const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(DerivedDecl);
Obj.getLValueOffset() += Layout.getVBaseClassOffset(BaseDecl);
Obj.addDecl(Info, E, BaseDecl, /*Virtual*/ true);
@@ -1331,24 +1336,29 @@
/// Update LVal to refer to the given field, which must be a member of the type
/// currently described by LVal.
-static void HandleLValueMember(EvalInfo &Info, const Expr *E, LValue &LVal,
+static bool HandleLValueMember(EvalInfo &Info, const Expr *E, LValue &LVal,
const FieldDecl *FD,
const ASTRecordLayout *RL = 0) {
- if (!RL)
+ if (!RL) {
+ if (FD->getParent()->isInvalidDecl()) return false;
RL = &Info.Ctx.getASTRecordLayout(FD->getParent());
+ }
unsigned I = FD->getFieldIndex();
LVal.Offset += Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I));
LVal.addDecl(Info, E, FD);
+ return true;
}
/// Update LVal to refer to the given indirect field.
-static void HandleLValueIndirectMember(EvalInfo &Info, const Expr *E,
+static bool HandleLValueIndirectMember(EvalInfo &Info, const Expr *E,
LValue &LVal,
const IndirectFieldDecl *IFD) {
for (IndirectFieldDecl::chain_iterator C = IFD->chain_begin(),
CE = IFD->chain_end(); C != CE; ++C)
- HandleLValueMember(Info, E, LVal, cast<FieldDecl>(*C));
+ if (!HandleLValueMember(Info, E, LVal, cast<FieldDecl>(*C)))
+ return false;
+ return true;
}
/// Get the size of the given type in char units.
@@ -1952,22 +1962,27 @@
// The first class in the path is that of the lvalue.
for (unsigned I = 1, N = MemPtr.Path.size(); I != N; ++I) {
const CXXRecordDecl *Base = MemPtr.Path[N - I - 1];
- HandleLValueDirectBase(Info, BO, LV, RD, Base);
+ if (!HandleLValueDirectBase(Info, BO, LV, RD, Base))
+ return 0;
RD = Base;
}
// Finally cast to the class containing the member.
- HandleLValueDirectBase(Info, BO, LV, RD, MemPtr.getContainingRecord());
+ if (!HandleLValueDirectBase(Info, BO, LV, RD, MemPtr.getContainingRecord()))
+ return 0;
}
// Add the member. Note that we cannot build bound member functions here.
if (IncludeMember) {
- if (const FieldDecl *FD = dyn_cast<FieldDecl>(MemPtr.getDecl()))
- HandleLValueMember(Info, BO, LV, FD);
- else if (const IndirectFieldDecl *IFD =
- dyn_cast<IndirectFieldDecl>(MemPtr.getDecl()))
- HandleLValueIndirectMember(Info, BO, LV, IFD);
- else
+ if (const FieldDecl *FD = dyn_cast<FieldDecl>(MemPtr.getDecl())) {
+ if (!HandleLValueMember(Info, BO, LV, FD))
+ return 0;
+ } else if (const IndirectFieldDecl *IFD =
+ dyn_cast<IndirectFieldDecl>(MemPtr.getDecl())) {
+ if (!HandleLValueIndirectMember(Info, BO, LV, IFD))
+ return 0;
+ } else {
llvm_unreachable("can't construct reference to bound member function");
+ }
}
return MemPtr.getDecl();
@@ -2189,6 +2204,7 @@
Result = APValue(APValue::UninitStruct(), RD->getNumBases(),
std::distance(RD->field_begin(), RD->field_end()));
+ if (RD->isInvalidDecl()) return false;
const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD);
bool Success = true;
@@ -2212,11 +2228,13 @@
"base class initializers not in expected order");
++BaseIt;
#endif
- HandleLValueDirectBase(Info, (*I)->getInit(), Subobject, RD,
- BaseType->getAsCXXRecordDecl(), &Layout);
+ if (!HandleLValueDirectBase(Info, (*I)->getInit(), Subobject, RD,
+ BaseType->getAsCXXRecordDecl(), &Layout))
+ return false;
Value = &Result.getStructBase(BasesSeen++);
} else if (FieldDecl *FD = (*I)->getMember()) {
- HandleLValueMember(Info, (*I)->getInit(), Subobject, FD, &Layout);
+ if (!HandleLValueMember(Info, (*I)->getInit(), Subobject, FD, &Layout))
+ return false;
if (RD->isUnion()) {
Result = APValue(FD);
Value = &Result.getUnionValue();
@@ -2244,7 +2262,8 @@
*Value = APValue(APValue::UninitStruct(), CD->getNumBases(),
std::distance(CD->field_begin(), CD->field_end()));
}
- HandleLValueMember(Info, (*I)->getInit(), Subobject, FD);
+ if (!HandleLValueMember(Info, (*I)->getInit(), Subobject, FD))
+ return false;
if (CD->isUnion())
Value = &Value->getUnionValue();
else
@@ -2773,9 +2792,11 @@
assert(BaseTy->getAs<RecordType>()->getDecl()->getCanonicalDecl() ==
FD->getParent()->getCanonicalDecl() && "record / field mismatch");
(void)BaseTy;
- HandleLValueMember(this->Info, E, Result, FD);
+ if (!HandleLValueMember(this->Info, E, Result, FD))
+ return false;
} else if (const IndirectFieldDecl *IFD = dyn_cast<IndirectFieldDecl>(MD)) {
- HandleLValueIndirectMember(this->Info, E, Result, IFD);
+ if (!HandleLValueIndirectMember(this->Info, E, Result, IFD))
+ return false;
} else
return this->Error(E);
@@ -3373,6 +3394,7 @@
Result = APValue(APValue::UninitStruct(), CD ? CD->getNumBases() : 0,
std::distance(RD->field_begin(), RD->field_end()));
+ if (RD->isInvalidDecl()) return false;
const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD);
if (CD) {
@@ -3381,7 +3403,8 @@
End = CD->bases_end(); I != End; ++I, ++Index) {
const CXXRecordDecl *Base = I->getType()->getAsCXXRecordDecl();
LValue Subobject = This;
- HandleLValueDirectBase(Info, E, Subobject, CD, Base, &Layout);
+ if (!HandleLValueDirectBase(Info, E, Subobject, CD, Base, &Layout))
+ return false;
if (!HandleClassZeroInitialization(Info, E, Base, Subobject,
Result.getStructBase(Index)))
return false;
@@ -3391,15 +3414,16 @@
for (RecordDecl::field_iterator I = RD->field_begin(), End = RD->field_end();
I != End; ++I) {
// -- if T is a reference type, no initialization is performed.
- if ((*I)->getType()->isReferenceType())
+ if (I->getType()->isReferenceType())
continue;
LValue Subobject = This;
- HandleLValueMember(Info, E, Subobject, *I, &Layout);
+ if (!HandleLValueMember(Info, E, Subobject, &*I, &Layout))
+ return false;
- ImplicitValueInitExpr VIE((*I)->getType());
+ ImplicitValueInitExpr VIE(I->getType());
if (!EvaluateInPlace(
- Result.getStructField((*I)->getFieldIndex()), Info, Subobject, &VIE))
+ Result.getStructField(I->getFieldIndex()), Info, Subobject, &VIE))
return false;
}
@@ -3419,9 +3443,10 @@
}
LValue Subobject = This;
- HandleLValueMember(Info, E, Subobject, *I);
- Result = APValue(*I);
- ImplicitValueInitExpr VIE((*I)->getType());
+ if (!HandleLValueMember(Info, E, Subobject, &*I))
+ return false;
+ Result = APValue(&*I);
+ ImplicitValueInitExpr VIE(I->getType());
return EvaluateInPlace(Result.getUnionValue(), Info, Subobject, &VIE);
}
@@ -3472,7 +3497,6 @@
const RecordDecl *RD = E->getType()->castAs<RecordType>()->getDecl();
if (RD->isInvalidDecl()) return false;
-
const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD);
if (RD->isUnion()) {
@@ -3487,7 +3511,8 @@
const Expr *InitExpr = E->getNumInits() ? E->getInit(0) : &VIE;
LValue Subobject = This;
- HandleLValueMember(Info, InitExpr, Subobject, Field, &Layout);
+ if (!HandleLValueMember(Info, InitExpr, Subobject, Field, &Layout))
+ return false;
return EvaluateInPlace(Result.getUnionValue(), Info, Subobject, InitExpr);
}
@@ -3510,15 +3535,16 @@
// FIXME: Diagnostics here should point to the end of the initializer
// list, not the start.
- HandleLValueMember(Info, HaveInit ? E->getInit(ElementNo) : E, Subobject,
- *Field, &Layout);
+ if (!HandleLValueMember(Info, HaveInit ? E->getInit(ElementNo) : E,
+ Subobject, &*Field, &Layout))
+ return false;
// Perform an implicit value-initialization for members beyond the end of
// the initializer list.
ImplicitValueInitExpr VIE(HaveInit ? Info.Ctx.IntTy : Field->getType());
if (!EvaluateInPlace(
- Result.getStructField((*Field)->getFieldIndex()),
+ Result.getStructField(Field->getFieldIndex()),
Info, Subobject, HaveInit ? E->getInit(ElementNo++) : &VIE)) {
if (!Info.keepEvaluatingAfterFailure())
return false;
@@ -5285,6 +5311,7 @@
if (!RT)
return Error(OOE);
RecordDecl *RD = RT->getDecl();
+ if (RD->isInvalidDecl()) return false;
const ASTRecordLayout &RL = Info.Ctx.getASTRecordLayout(RD);
unsigned i = MemberDecl->getFieldIndex();
assert(i < RL.getFieldCount() && "offsetof field in wrong type");
@@ -5306,6 +5333,7 @@
if (!RT)
return Error(OOE);
RecordDecl *RD = RT->getDecl();
+ if (RD->isInvalidDecl()) return false;
const ASTRecordLayout &RL = Info.Ctx.getASTRecordLayout(RD);
// Find the base class itself.
Modified: cfe/branches/tooling/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/ItaniumMangle.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/branches/tooling/lib/AST/ItaniumMangle.cpp Tue May 8 03:47:31 2012
@@ -1032,7 +1032,7 @@
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I) {
- const FieldDecl *FD = *I;
+ const FieldDecl *FD = &*I;
if (FD->getIdentifier())
return FD;
Modified: cfe/branches/tooling/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/MicrosoftMangle.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/branches/tooling/lib/AST/MicrosoftMangle.cpp Tue May 8 03:47:31 2012
@@ -763,12 +763,16 @@
Out << 'X';
} else {
if (D) {
- // If we got a decl, use the "types-as-written" to make sure arrays
- // get mangled right.
+ // If we got a decl, use the type-as-written to make sure arrays
+ // get mangled right. Note that we can't rely on the TSI
+ // existing if (for example) the parameter was synthesized.
for (FunctionDecl::param_const_iterator Parm = D->param_begin(),
- ParmEnd = D->param_end();
- Parm != ParmEnd; ++Parm)
- mangleType((*Parm)->getTypeSourceInfo()->getType());
+ ParmEnd = D->param_end(); Parm != ParmEnd; ++Parm) {
+ if (TypeSourceInfo *typeAsWritten = (*Parm)->getTypeSourceInfo())
+ mangleType(typeAsWritten->getType());
+ else
+ mangleType((*Parm)->getType());
+ }
} else {
for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
ArgEnd = Proto->arg_type_end();
Modified: cfe/branches/tooling/lib/AST/RecordLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/RecordLayout.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/RecordLayout.cpp (original)
+++ cfe/branches/tooling/lib/AST/RecordLayout.cpp Tue May 8 03:47:31 2012
@@ -32,7 +32,7 @@
CharUnits alignment, CharUnits datasize,
const uint64_t *fieldoffsets,
unsigned fieldcount)
- : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
+ : Size(size), DataSize(datasize), Alignment(alignment), FieldOffsets(0),
FieldCount(fieldcount), CXXInfo(0) {
if (FieldCount > 0) {
FieldOffsets = new (Ctx) uint64_t[FieldCount];
@@ -43,7 +43,7 @@
// Constructor for C++ records.
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx,
CharUnits size, CharUnits alignment,
- CharUnits vfptroffset, CharUnits vbptroffset,
+ bool hasOwnVFPtr, CharUnits vbptroffset,
CharUnits datasize,
const uint64_t *fieldoffsets,
unsigned fieldcount,
@@ -53,8 +53,8 @@
const CXXRecordDecl *PrimaryBase,
bool IsPrimaryBaseVirtual,
const BaseOffsetsMapTy& BaseOffsets,
- const BaseOffsetsMapTy& VBaseOffsets)
- : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
+ const VBaseOffsetsMapTy& VBaseOffsets)
+ : Size(size), DataSize(datasize), Alignment(alignment), FieldOffsets(0),
FieldCount(fieldcount), CXXInfo(new (Ctx) CXXRecordLayoutInfo)
{
if (FieldCount > 0) {
@@ -69,7 +69,7 @@
CXXInfo->SizeOfLargestEmptySubobject = SizeOfLargestEmptySubobject;
CXXInfo->BaseOffsets = BaseOffsets;
CXXInfo->VBaseOffsets = VBaseOffsets;
- CXXInfo->VFPtrOffset = vfptroffset;
+ CXXInfo->HasOwnVFPtr = hasOwnVFPtr;
CXXInfo->VBPtrOffset = vbptroffset;
#ifndef NDEBUG
Modified: cfe/branches/tooling/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/RecordLayoutBuilder.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/branches/tooling/lib/AST/RecordLayoutBuilder.cpp Tue May 8 03:47:31 2012
@@ -161,10 +161,10 @@
// Check the fields.
for (CXXRecordDecl::field_iterator I = Class->field_begin(),
E = Class->field_end(); I != E; ++I) {
- const FieldDecl *FD = *I;
+ const FieldDecl &FD = *I;
const RecordType *RT =
- Context.getBaseElementType(FD->getType())->getAs<RecordType>();
+ Context.getBaseElementType(FD.getType())->getAs<RecordType>();
// We only care about record types.
if (!RT)
@@ -261,7 +261,7 @@
unsigned FieldNo = 0;
for (CXXRecordDecl::field_iterator I = Info->Class->field_begin(),
E = Info->Class->field_end(); I != E; ++I, ++FieldNo) {
- const FieldDecl *FD = *I;
+ const FieldDecl *FD = &*I;
if (FD->isBitField())
continue;
@@ -310,7 +310,7 @@
unsigned FieldNo = 0;
for (CXXRecordDecl::field_iterator I = Info->Class->field_begin(),
E = Info->Class->field_end(); I != E; ++I, ++FieldNo) {
- const FieldDecl *FD = *I;
+ const FieldDecl *FD = &*I;
if (FD->isBitField())
continue;
@@ -380,7 +380,7 @@
unsigned FieldNo = 0;
for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I, ++FieldNo) {
- const FieldDecl *FD = *I;
+ const FieldDecl *FD = &*I;
if (FD->isBitField())
continue;
@@ -491,7 +491,7 @@
unsigned FieldNo = 0;
for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I, ++FieldNo) {
- const FieldDecl *FD = *I;
+ const FieldDecl *FD = &*I;
if (FD->isBitField())
continue;
@@ -538,6 +538,8 @@
}
}
+typedef llvm::SmallPtrSet<const CXXRecordDecl*, 4> ClassSetTy;
+
class RecordLayoutBuilder {
protected:
// FIXME: Remove this and make the appropriate fields public.
@@ -600,8 +602,9 @@
/// out is virtual.
bool PrimaryBaseIsVirtual;
- /// VFPtrOffset - Virtual function table offset. Only for MS layout.
- CharUnits VFPtrOffset;
+ /// HasOwnVFPtr - Whether the class provides its own vtable/vftbl
+ /// pointer, as opposed to inheriting one from a primary base class.
+ bool HasOwnVFPtr;
/// VBPtrOffset - Virtual base table offset. Only for MS layout.
CharUnits VBPtrOffset;
@@ -612,7 +615,7 @@
BaseOffsetsMapTy Bases;
// VBases - virtual base classes and their offsets in the record.
- BaseOffsetsMapTy VBases;
+ ASTRecordLayout::VBaseOffsetsMapTy VBases;
/// IndirectPrimaryBases - Virtual base classes, direct or indirect, that are
/// primary base classes for some other direct or indirect base class.
@@ -652,7 +655,7 @@
NonVirtualAlignment(CharUnits::One()),
ZeroLengthBitfield(0), PrimaryBase(0),
PrimaryBaseIsVirtual(false),
- VFPtrOffset(CharUnits::fromQuantity(-1)),
+ HasOwnVFPtr(false),
VBPtrOffset(CharUnits::fromQuantity(-1)),
FirstNearlyEmptyVBase(0) { }
@@ -725,15 +728,20 @@
CharUnits Offset);
bool needsVFTable(const CXXRecordDecl *RD) const;
- bool hasNewVirtualFunction(const CXXRecordDecl *RD) const;
+ bool hasNewVirtualFunction(const CXXRecordDecl *RD,
+ bool IgnoreDestructor = false) const;
bool isPossiblePrimaryBase(const CXXRecordDecl *Base) const;
+ void computeVtordisps(const CXXRecordDecl *RD,
+ ClassSetTy &VtordispVBases);
+
/// LayoutVirtualBases - Lays out all the virtual bases.
void LayoutVirtualBases(const CXXRecordDecl *RD,
const CXXRecordDecl *MostDerivedClass);
/// LayoutVirtualBase - Lays out a single virtual base.
- void LayoutVirtualBase(const BaseSubobjectInfo *Base);
+ void LayoutVirtualBase(const BaseSubobjectInfo *Base,
+ bool IsVtordispNeed = false);
/// LayoutBase - Will lay out a base and return the offset where it was
/// placed, in chars.
@@ -1044,8 +1052,7 @@
CharUnits PtrAlign =
Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerAlign(0));
EnsureVTablePointerAlignment(PtrAlign);
- if (isMicrosoftCXXABI())
- VFPtrOffset = getSize();
+ HasOwnVFPtr = true;
setSize(getSize() + PtrWidth);
setDataSize(getSize());
}
@@ -1142,7 +1149,7 @@
assert(!VBases.count(Info->PrimaryVirtualBaseInfo->Class) &&
"primary vbase offset already exists!");
VBases.insert(std::make_pair(Info->PrimaryVirtualBaseInfo->Class,
- Offset));
+ ASTRecordLayout::VBaseInfo(Offset, false)));
// Traverse the primary virtual base.
AddPrimaryVirtualBaseOffsets(Info->PrimaryVirtualBaseInfo, Offset);
@@ -1193,19 +1200,177 @@
return hasNewVirtualFunction(RD);
}
+/// Does the given class inherit non-virtually from any of the classes
+/// in the given set?
+static bool hasNonVirtualBaseInSet(const CXXRecordDecl *RD,
+ const ClassSetTy &set) {
+ for (CXXRecordDecl::base_class_const_iterator
+ I = RD->bases_begin(), E = RD->bases_end(); I != E; ++I) {
+ // Ignore virtual links.
+ if (I->isVirtual()) continue;
+
+ // Check whether the set contains the base.
+ const CXXRecordDecl *base = I->getType()->getAsCXXRecordDecl();
+ if (set.count(base))
+ return true;
+
+ // Otherwise, recurse and propagate.
+ if (hasNonVirtualBaseInSet(base, set))
+ return true;
+ }
+
+ return false;
+}
+
+/// Does the given method (B::foo()) already override a method (A::foo())
+/// such that A requires a vtordisp in B? If so, we don't need to add a
+/// new vtordisp for B in a yet-more-derived class C providing C::foo().
+static bool overridesMethodRequiringVtorDisp(const ASTContext &Context,
+ const CXXMethodDecl *M) {
+ CXXMethodDecl::method_iterator
+ I = M->begin_overridden_methods(), E = M->end_overridden_methods();
+ if (I == E) return false;
+
+ const ASTRecordLayout::VBaseOffsetsMapTy &offsets =
+ Context.getASTRecordLayout(M->getParent()).getVBaseOffsetsMap();
+ do {
+ const CXXMethodDecl *overridden = *I;
+
+ // If the overridden method's class isn't recognized as a virtual
+ // base in the derived class, ignore it.
+ ASTRecordLayout::VBaseOffsetsMapTy::const_iterator
+ it = offsets.find(overridden->getParent());
+ if (it == offsets.end()) continue;
+
+ // Otherwise, check if the overridden method's class needs a vtordisp.
+ if (it->second.hasVtorDisp()) return true;
+
+ } while (++I != E);
+ return false;
+}
+
+/// In the Microsoft ABI, decide which of the virtual bases require a
+/// vtordisp field.
+void RecordLayoutBuilder::computeVtordisps(const CXXRecordDecl *RD,
+ ClassSetTy &vtordispVBases) {
+ // Bail out if we have no virtual bases.
+ assert(RD->getNumVBases());
+
+ // Build up the set of virtual bases that we haven't decided yet.
+ ClassSetTy undecidedVBases;
+ for (CXXRecordDecl::base_class_const_iterator
+ I = RD->vbases_begin(), E = RD->vbases_end(); I != E; ++I) {
+ const CXXRecordDecl *vbase = I->getType()->getAsCXXRecordDecl();
+ undecidedVBases.insert(vbase);
+ }
+ assert(!undecidedVBases.empty());
+
+ // A virtual base requires a vtordisp field in a derived class if it
+ // requires a vtordisp field in a base class. Walk all the direct
+ // bases and collect this information.
+ for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
+ E = RD->bases_end(); I != E; ++I) {
+ const CXXRecordDecl *base = I->getType()->getAsCXXRecordDecl();
+ const ASTRecordLayout &baseLayout = Context.getASTRecordLayout(base);
+
+ // Iterate over the set of virtual bases provided by this class.
+ for (ASTRecordLayout::VBaseOffsetsMapTy::const_iterator
+ VI = baseLayout.getVBaseOffsetsMap().begin(),
+ VE = baseLayout.getVBaseOffsetsMap().end(); VI != VE; ++VI) {
+ // If it doesn't need a vtordisp in this base, ignore it.
+ if (!VI->second.hasVtorDisp()) continue;
+
+ // If we've already seen it and decided it needs a vtordisp, ignore it.
+ if (!undecidedVBases.erase(VI->first))
+ continue;
+
+ // Add it.
+ vtordispVBases.insert(VI->first);
+
+ // Quit as soon as we've decided everything.
+ if (undecidedVBases.empty())
+ return;
+ }
+ }
+
+ // Okay, we have virtual bases that we haven't yet decided about. A
+ // virtual base requires a vtordisp if any the non-destructor
+ // virtual methods declared in this class directly override a method
+ // provided by that virtual base. (If so, we need to emit a thunk
+ // for that method, to be used in the construction vftable, which
+ // applies an additional 'vtordisp' this-adjustment.)
+
+ // Collect the set of bases directly overridden by any method in this class.
+ // It's possible that some of these classes won't be virtual bases, or won't be
+ // provided by virtual bases, or won't be virtual bases in the overridden
+ // instance but are virtual bases elsewhere. Only the last matters for what
+ // we're doing, and we can ignore those: if we don't directly override
+ // a method provided by a virtual copy of a base class, but we do directly
+ // override a method provided by a non-virtual copy of that base class,
+ // then we must indirectly override the method provided by the virtual base,
+ // and so we should already have collected it in the loop above.
+ ClassSetTy overriddenBases;
+ for (CXXRecordDecl::method_iterator
+ M = RD->method_begin(), E = RD->method_end(); M != E; ++M) {
+ // Ignore non-virtual methods and destructors.
+ if (isa<CXXDestructorDecl>(*M) || !M->isVirtual())
+ continue;
+
+ for (CXXMethodDecl::method_iterator I = M->begin_overridden_methods(),
+ E = M->end_overridden_methods(); I != E; ++I) {
+ const CXXMethodDecl *overriddenMethod = (*I);
+
+ // Ignore methods that override methods from vbases that require
+ // require vtordisps.
+ if (overridesMethodRequiringVtorDisp(Context, overriddenMethod))
+ continue;
+
+ // As an optimization, check immediately whether we're overriding
+ // something from the undecided set.
+ const CXXRecordDecl *overriddenBase = overriddenMethod->getParent();
+ if (undecidedVBases.erase(overriddenBase)) {
+ vtordispVBases.insert(overriddenBase);
+ if (undecidedVBases.empty()) return;
+
+ // We can't 'continue;' here because one of our undecided
+ // vbases might non-virtually inherit from this base.
+ // Consider:
+ // struct A { virtual void foo(); };
+ // struct B : A {};
+ // struct C : virtual A, virtual B { virtual void foo(); };
+ // We need a vtordisp for B here.
+ }
+
+ // Otherwise, just collect it.
+ overriddenBases.insert(overriddenBase);
+ }
+ }
+
+ // Walk the undecided v-bases and check whether they (non-virtually)
+ // provide any of the overridden bases. We don't need to consider
+ // virtual links because the vtordisp inheres to the layout
+ // subobject containing the base.
+ for (ClassSetTy::const_iterator
+ I = undecidedVBases.begin(), E = undecidedVBases.end(); I != E; ++I) {
+ if (hasNonVirtualBaseInSet(*I, overriddenBases))
+ vtordispVBases.insert(*I);
+ }
+}
+
/// hasNewVirtualFunction - Does the given polymorphic class declare a
/// virtual function that does not override a method from any of its
/// base classes?
bool
-RecordLayoutBuilder::hasNewVirtualFunction(const CXXRecordDecl *RD) const {
- assert(RD->isPolymorphic());
+RecordLayoutBuilder::hasNewVirtualFunction(const CXXRecordDecl *RD,
+ bool IgnoreDestructor) const {
if (!RD->getNumBases())
return true;
for (CXXRecordDecl::method_iterator method = RD->method_begin();
method != RD->method_end();
++method) {
- if (method->isVirtual() && !method->size_overridden_methods()) {
+ if (method->isVirtual() && !method->size_overridden_methods() &&
+ !(IgnoreDestructor && method->getKind() == Decl::CXXDestructor)) {
return true;
}
}
@@ -1215,11 +1380,11 @@
/// isPossiblePrimaryBase - Is the given base class an acceptable
/// primary base class?
bool
-RecordLayoutBuilder::isPossiblePrimaryBase(const CXXRecordDecl *Base) const {
+RecordLayoutBuilder::isPossiblePrimaryBase(const CXXRecordDecl *base) const {
// In the Itanium ABI, a class can be a primary base class if it has
// a vtable for any reason.
if (!isMicrosoftCXXABI())
- return Base->isDynamicClass();
+ return base->isDynamicClass();
// In the MS ABI, a class can only be a primary base class if it
// provides a vf-table at a static offset. That means it has to be
@@ -1228,14 +1393,22 @@
// base, which we have to guard against.
// First off, it has to have virtual functions.
- if (!Base->isPolymorphic()) return false;
+ if (!base->isPolymorphic()) return false;
- // If it has no virtual bases, then everything is at a static offset.
- if (!Base->getNumVBases()) return true;
+ // If it has no virtual bases, then the vfptr must be at a static offset.
+ if (!base->getNumVBases()) return true;
+
+ // Otherwise, the necessary information is cached in the layout.
+ const ASTRecordLayout &layout = Context.getASTRecordLayout(base);
- // Okay, just ask the base class's layout.
- return (Context.getASTRecordLayout(Base).getVFPtrOffset()
- != CharUnits::fromQuantity(-1));
+ // If the base has its own vfptr, it can be a primary base.
+ if (layout.hasOwnVFPtr()) return true;
+
+ // If the base has a primary base class, then it can be a primary base.
+ if (layout.getPrimaryBase()) return true;
+
+ // Otherwise it can't.
+ return false;
}
void
@@ -1288,10 +1461,12 @@
}
void RecordLayoutBuilder::MSLayoutVirtualBases(const CXXRecordDecl *RD) {
-
if (!RD->getNumVBases())
return;
+ ClassSetTy VtordispVBases;
+ computeVtordisps(RD, VtordispVBases);
+
// This is substantially simplified because there are no virtual
// primary bases.
for (CXXRecordDecl::base_class_const_iterator I = RD->vbases_begin(),
@@ -1299,12 +1474,25 @@
const CXXRecordDecl *BaseDecl = I->getType()->getAsCXXRecordDecl();
const BaseSubobjectInfo *BaseInfo = VirtualBaseInfo.lookup(BaseDecl);
assert(BaseInfo && "Did not find virtual base info!");
-
- LayoutVirtualBase(BaseInfo);
+
+ // If this base requires a vtordisp, add enough space for an int field.
+ // This is apparently always 32-bits, even on x64.
+ bool vtordispNeeded = false;
+ if (VtordispVBases.count(BaseDecl)) {
+ CharUnits IntSize =
+ CharUnits::fromQuantity(Context.getTargetInfo().getIntWidth() / 8);
+
+ setSize(getSize() + IntSize);
+ setDataSize(getSize());
+ vtordispNeeded = true;
+ }
+
+ LayoutVirtualBase(BaseInfo, vtordispNeeded);
}
}
-void RecordLayoutBuilder::LayoutVirtualBase(const BaseSubobjectInfo *Base) {
+void RecordLayoutBuilder::LayoutVirtualBase(const BaseSubobjectInfo *Base,
+ bool IsVtordispNeed) {
assert(!Base->Derived && "Trying to lay out a primary virtual base!");
// Layout the base.
@@ -1312,9 +1500,11 @@
// Add its base class offset.
assert(!VBases.count(Base->Class) && "vbase offset already exists!");
- VBases.insert(std::make_pair(Base->Class, Offset));
-
- AddPrimaryVirtualBaseOffsets(Base, Offset);
+ VBases.insert(std::make_pair(Base->Class,
+ ASTRecordLayout::VBaseInfo(Offset, IsVtordispNeed)));
+
+ if (!isMicrosoftCXXABI())
+ AddPrimaryVirtualBaseOffsets(Base, Offset);
}
CharUnits RecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) {
@@ -1461,8 +1651,8 @@
Context.getTargetInfo().getCharAlign()));
NonVirtualAlignment = Alignment;
- if (isMicrosoftCXXABI() &&
- NonVirtualSize != NonVirtualSize.RoundUpToAlignment(Alignment)) {
+ if (isMicrosoftCXXABI()) {
+ if (NonVirtualSize != NonVirtualSize.RoundUpToAlignment(Alignment)) {
CharUnits AlignMember =
NonVirtualSize.RoundUpToAlignment(Alignment) - NonVirtualSize;
@@ -1472,9 +1662,9 @@
NonVirtualSize = Context.toCharUnitsFromBits(
llvm::RoundUpToAlignment(getSizeInBits(),
Context.getTargetInfo().getCharAlign()));
+ }
MSLayoutVirtualBases(RD);
-
} else {
// Lay out the virtual bases and add the primary virtual base offsets.
LayoutVirtualBases(RD, RD);
@@ -1540,7 +1730,7 @@
for (RecordDecl::field_iterator Field = D->field_begin(),
FieldEnd = D->field_end(); Field != FieldEnd; ++Field) {
if (IsMsStruct) {
- FieldDecl *FD = (*Field);
+ FieldDecl *FD = &*Field;
if (Context.ZeroBitfieldFollowsBitfield(FD, LastFD))
ZeroLengthBitfield = FD;
// Zero-length bitfields following non-bitfield members are
@@ -1635,11 +1825,11 @@
}
else if (!Context.getTargetInfo().useBitFieldTypeAlignment() &&
Context.getTargetInfo().useZeroLengthBitfieldAlignment()) {
- FieldDecl *FD = (*Field);
+ FieldDecl *FD = &*Field;
if (FD->isBitField() && FD->getBitWidthValue(Context) == 0)
ZeroLengthBitfield = FD;
}
- LayoutField(*Field);
+ LayoutField(&*Field);
}
if (IsMsStruct && RemainingInAlignment &&
LastFD && LastFD->isBitField() && LastFD->getBitWidthValue(Context)) {
@@ -2147,7 +2337,7 @@
for (CXXRecordDecl::method_iterator I = RD->method_begin(),
E = RD->method_end(); I != E; ++I) {
- const CXXMethodDecl *MD = *I;
+ const CXXMethodDecl *MD = &*I;
if (!MD->isVirtual())
continue;
@@ -2238,7 +2428,7 @@
NewEntry =
new (*this) ASTRecordLayout(*this, Builder.getSize(),
Builder.Alignment,
- Builder.VFPtrOffset,
+ Builder.HasOwnVFPtr,
Builder.VBPtrOffset,
DataSize,
Builder.FieldOffsets.data(),
@@ -2375,7 +2565,7 @@
IndentLevel++;
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
- bool HasVfptr = Layout.getVFPtrOffset() != CharUnits::fromQuantity(-1);
+ bool HasVfptr = Layout.hasOwnVFPtr();
bool HasVbptr = Layout.getVBPtrOffset() != CharUnits::fromQuantity(-1);
// Vtable pointer.
@@ -2405,7 +2595,7 @@
// vfptr and vbptr (for Microsoft C++ ABI)
if (HasVfptr) {
- PrintOffset(OS, Offset + Layout.getVFPtrOffset(), IndentLevel);
+ PrintOffset(OS, Offset, IndentLevel);
OS << '(' << *RD << " vftable pointer)\n";
}
if (HasVbptr) {
@@ -2417,27 +2607,29 @@
uint64_t FieldNo = 0;
for (CXXRecordDecl::field_iterator I = RD->field_begin(),
E = RD->field_end(); I != E; ++I, ++FieldNo) {
- const FieldDecl *Field = *I;
+ const FieldDecl &Field = *I;
CharUnits FieldOffset = Offset +
C.toCharUnitsFromBits(Layout.getFieldOffset(FieldNo));
- if (const RecordType *RT = Field->getType()->getAs<RecordType>()) {
+ if (const RecordType *RT = Field.getType()->getAs<RecordType>()) {
if (const CXXRecordDecl *D = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
DumpCXXRecordLayout(OS, D, C, FieldOffset, IndentLevel,
- Field->getName().data(),
+ Field.getName().data(),
/*IncludeVirtualBases=*/true);
continue;
}
}
PrintOffset(OS, FieldOffset, IndentLevel);
- OS << Field->getType().getAsString() << ' ' << *Field << '\n';
+ OS << Field.getType().getAsString() << ' ' << Field << '\n';
}
if (!IncludeVirtualBases)
return;
// Dump virtual bases.
+ const ASTRecordLayout::VBaseOffsetsMapTy &vtordisps =
+ Layout.getVBaseOffsetsMap();
for (CXXRecordDecl::base_class_const_iterator I = RD->vbases_begin(),
E = RD->vbases_end(); I != E; ++I) {
assert(I->isVirtual() && "Found non-virtual class!");
@@ -2445,6 +2637,12 @@
cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl());
CharUnits VBaseOffset = Offset + Layout.getVBaseClassOffset(VBase);
+
+ if (vtordisps.find(VBase)->second.hasVtorDisp()) {
+ PrintOffset(OS, VBaseOffset - CharUnits::fromQuantity(4), IndentLevel);
+ OS << "(vtordisp for vbase " << *VBase << ")\n";
+ }
+
DumpCXXRecordLayout(OS, VBase, C, VBaseOffset, IndentLevel,
VBase == PrimaryBase ?
"(primary virtual base)" : "(virtual base)",
Modified: cfe/branches/tooling/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/Type.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/Type.cpp (original)
+++ cfe/branches/tooling/lib/AST/Type.cpp Tue May 8 03:47:31 2012
@@ -895,6 +895,14 @@
}
bool QualType::isPODType(ASTContext &Context) const {
+ // C++11 has a more relaxed definition of POD.
+ if (Context.getLangOpts().CPlusPlus0x)
+ return isCXX11PODType(Context);
+
+ return isCXX98PODType(Context);
+}
+
+bool QualType::isCXX98PODType(ASTContext &Context) const {
// The compiler shouldn't query this for incomplete types, but the user might.
// We return false for that case. Except for incomplete arrays of PODs, which
// are PODs according to the standard.
@@ -902,7 +910,7 @@
return 0;
if ((*this)->isIncompleteArrayType())
- return Context.getBaseElementType(*this).isPODType(Context);
+ return Context.getBaseElementType(*this).isCXX98PODType(Context);
if ((*this)->isIncompleteType())
return false;
@@ -929,7 +937,7 @@
case Type::VariableArray:
case Type::ConstantArray:
// IncompleteArray is handled above.
- return Context.getBaseElementType(*this).isPODType(Context);
+ return Context.getBaseElementType(*this).isCXX98PODType(Context);
case Type::ObjCObjectPointer:
case Type::BlockPointer:
@@ -1417,7 +1425,7 @@
llvm_unreachable("Invalid type class.");
}
-const char *BuiltinType::getName(const PrintingPolicy &Policy) const {
+StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
switch (getKind()) {
case Void: return "void";
case Bool: return Policy.Bool ? "bool" : "_Bool";
Modified: cfe/branches/tooling/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/TypePrinter.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/TypePrinter.cpp (original)
+++ cfe/branches/tooling/lib/AST/TypePrinter.cpp Tue May 8 03:47:31 2012
@@ -19,8 +19,10 @@
#include "clang/AST/PrettyPrinter.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/SaveAndRestore.h"
using namespace clang;
namespace {
@@ -40,62 +42,124 @@
Policy.SuppressStrongLifetime = Old;
}
};
+
+ class ParamPolicyRAII {
+ PrintingPolicy &Policy;
+ bool Old;
+
+ public:
+ explicit ParamPolicyRAII(PrintingPolicy &Policy)
+ : Policy(Policy), Old(Policy.SuppressSpecifiers) {
+ Policy.SuppressSpecifiers = false;
+ }
+
+ ~ParamPolicyRAII() {
+ Policy.SuppressSpecifiers = Old;
+ }
+ };
+
+ class ElaboratedTypePolicyRAII {
+ PrintingPolicy &Policy;
+ bool SuppressTagKeyword;
+ bool SuppressScope;
+
+ public:
+ explicit ElaboratedTypePolicyRAII(PrintingPolicy &Policy) : Policy(Policy) {
+ SuppressTagKeyword = Policy.SuppressTagKeyword;
+ SuppressScope = Policy.SuppressScope;
+ Policy.SuppressTagKeyword = true;
+ Policy.SuppressScope = true;
+ }
+
+ ~ElaboratedTypePolicyRAII() {
+ Policy.SuppressTagKeyword = SuppressTagKeyword;
+ Policy.SuppressScope = SuppressScope;
+ }
+ };
class TypePrinter {
PrintingPolicy Policy;
+ bool HasEmptyPlaceHolder;
public:
- explicit TypePrinter(const PrintingPolicy &Policy) : Policy(Policy) { }
+ explicit TypePrinter(const PrintingPolicy &Policy)
+ : Policy(Policy), HasEmptyPlaceHolder(false) { }
- void print(const Type *ty, Qualifiers qs, std::string &buffer);
- void print(QualType T, std::string &S);
- void AppendScope(DeclContext *DC, std::string &S);
- void printTag(TagDecl *T, std::string &S);
+ void print(const Type *ty, Qualifiers qs, raw_ostream &OS,
+ StringRef PlaceHolder);
+ void print(QualType T, raw_ostream &OS, StringRef PlaceHolder);
+
+ static bool canPrefixQualifiers(const Type *T, bool &NeedARCStrongQualifier);
+ void spaceBeforePlaceHolder(raw_ostream &OS);
+ void printTypeSpec(const NamedDecl *D, raw_ostream &OS);
+
+ void printBefore(const Type *ty, Qualifiers qs, raw_ostream &OS);
+ void printBefore(QualType T, raw_ostream &OS);
+ void printAfter(const Type *ty, Qualifiers qs, raw_ostream &OS);
+ void printAfter(QualType T, raw_ostream &OS);
+ void AppendScope(DeclContext *DC, raw_ostream &OS);
+ void printTag(TagDecl *T, raw_ostream &OS);
#define ABSTRACT_TYPE(CLASS, PARENT)
#define TYPE(CLASS, PARENT) \
- void print##CLASS(const CLASS##Type *T, std::string &S);
+ void print##CLASS##Before(const CLASS##Type *T, raw_ostream &OS); \
+ void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS);
#include "clang/AST/TypeNodes.def"
};
}
-static void AppendTypeQualList(std::string &S, unsigned TypeQuals) {
+static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals) {
+ bool appendSpace = false;
if (TypeQuals & Qualifiers::Const) {
- if (!S.empty()) S += ' ';
- S += "const";
+ OS << "const";
+ appendSpace = true;
}
if (TypeQuals & Qualifiers::Volatile) {
- if (!S.empty()) S += ' ';
- S += "volatile";
+ if (appendSpace) OS << ' ';
+ OS << "volatile";
+ appendSpace = true;
}
if (TypeQuals & Qualifiers::Restrict) {
- if (!S.empty()) S += ' ';
- S += "restrict";
+ if (appendSpace) OS << ' ';
+ OS << "restrict";
}
}
-void TypePrinter::print(QualType t, std::string &buffer) {
+void TypePrinter::spaceBeforePlaceHolder(raw_ostream &OS) {
+ if (!HasEmptyPlaceHolder)
+ OS << ' ';
+}
+
+void TypePrinter::print(QualType t, raw_ostream &OS, StringRef PlaceHolder) {
SplitQualType split = t.split();
- print(split.Ty, split.Quals, buffer);
+ print(split.Ty, split.Quals, OS, PlaceHolder);
}
-void TypePrinter::print(const Type *T, Qualifiers Quals, std::string &buffer) {
+void TypePrinter::print(const Type *T, Qualifiers Quals, raw_ostream &OS,
+ StringRef PlaceHolder) {
if (!T) {
- buffer += "NULL TYPE";
+ OS << "NULL TYPE";
return;
}
if (Policy.SuppressSpecifiers && T->isSpecifierType())
return;
-
- // Print qualifiers as appropriate.
-
+
+ SaveAndRestore<bool> PHVal(HasEmptyPlaceHolder, PlaceHolder.empty());
+
+ printBefore(T, Quals, OS);
+ OS << PlaceHolder;
+ printAfter(T, Quals, OS);
+}
+
+bool TypePrinter::canPrefixQualifiers(const Type *T,
+ bool &NeedARCStrongQualifier) {
// CanPrefixQualifiers - We prefer to print type qualifiers before the type,
// so that we get "const int" instead of "int const", but we can't do this if
// the type is complex. For example if the type is "int*", we *must* print
// "int * const", printing "const int *" is different. Only do this when the
// type expands to a simple string.
bool CanPrefixQualifiers = false;
- bool NeedARCStrongQualifier = false;
+ NeedARCStrongQualifier = false;
Type::TypeClass TC = T->getTypeClass();
if (const AutoType *AT = dyn_cast<AutoType>(T))
TC = AT->desugar()->getTypeClass();
@@ -157,493 +221,608 @@
CanPrefixQualifiers = false;
break;
}
-
- if (!CanPrefixQualifiers && !Quals.empty()) {
- std::string qualsBuffer;
+
+ return CanPrefixQualifiers;
+}
+
+void TypePrinter::printBefore(QualType t, raw_ostream &OS) {
+ SplitQualType split = t.split();
+ printBefore(split.Ty, split.Quals, OS);
+}
+
+/// \brief Prints the part of the type string before an identifier, e.g. for
+/// "int foo[10]" it prints "int ".
+void TypePrinter::printBefore(const Type *T,Qualifiers Quals, raw_ostream &OS) {
+ if (Policy.SuppressSpecifiers && T->isSpecifierType())
+ return;
+
+ SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder);
+
+ // Print qualifiers as appropriate.
+
+ bool CanPrefixQualifiers = false;
+ bool NeedARCStrongQualifier = false;
+ CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
+
+ if (CanPrefixQualifiers && !Quals.empty()) {
if (NeedARCStrongQualifier) {
IncludeStrongLifetimeRAII Strong(Policy);
- Quals.getAsStringInternal(qualsBuffer, Policy);
+ Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
} else {
- Quals.getAsStringInternal(qualsBuffer, Policy);
- }
-
- if (!qualsBuffer.empty()) {
- if (!buffer.empty()) {
- qualsBuffer += ' ';
- qualsBuffer += buffer;
- }
- std::swap(buffer, qualsBuffer);
+ Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/true);
}
}
-
+
+ bool hasAfterQuals = false;
+ if (!CanPrefixQualifiers && !Quals.empty()) {
+ hasAfterQuals = !Quals.isEmptyWhenPrinted(Policy);
+ if (hasAfterQuals)
+ HasEmptyPlaceHolder = false;
+ }
+
switch (T->getTypeClass()) {
#define ABSTRACT_TYPE(CLASS, PARENT)
#define TYPE(CLASS, PARENT) case Type::CLASS: \
- print##CLASS(cast<CLASS##Type>(T), buffer); \
+ print##CLASS##Before(cast<CLASS##Type>(T), OS); \
break;
#include "clang/AST/TypeNodes.def"
}
-
- // If we're adding the qualifiers as a prefix, do it now.
- if (CanPrefixQualifiers && !Quals.empty()) {
- std::string qualsBuffer;
+
+ if (hasAfterQuals) {
if (NeedARCStrongQualifier) {
IncludeStrongLifetimeRAII Strong(Policy);
- Quals.getAsStringInternal(qualsBuffer, Policy);
+ Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
} else {
- Quals.getAsStringInternal(qualsBuffer, Policy);
- }
-
- if (!qualsBuffer.empty()) {
- if (!buffer.empty()) {
- qualsBuffer += ' ';
- qualsBuffer += buffer;
- }
- std::swap(buffer, qualsBuffer);
+ Quals.print(OS, Policy, /*appendSpaceIfNonEmpty=*/!PrevPHIsEmpty.get());
}
}
}
-void TypePrinter::printBuiltin(const BuiltinType *T, std::string &S) {
- if (S.empty()) {
- S = T->getName(Policy);
- } else {
- // Prefix the basic type, e.g. 'int X'.
- S = ' ' + S;
- S = T->getName(Policy) + S;
+void TypePrinter::printAfter(QualType t, raw_ostream &OS) {
+ SplitQualType split = t.split();
+ printAfter(split.Ty, split.Quals, OS);
+}
+
+/// \brief Prints the part of the type string after an identifier, e.g. for
+/// "int foo[10]" it prints "[10]".
+void TypePrinter::printAfter(const Type *T, Qualifiers Quals, raw_ostream &OS) {
+ switch (T->getTypeClass()) {
+#define ABSTRACT_TYPE(CLASS, PARENT)
+#define TYPE(CLASS, PARENT) case Type::CLASS: \
+ print##CLASS##After(cast<CLASS##Type>(T), OS); \
+ break;
+#include "clang/AST/TypeNodes.def"
}
}
-void TypePrinter::printComplex(const ComplexType *T, std::string &S) {
- print(T->getElementType(), S);
- S = "_Complex " + S;
+void TypePrinter::printBuiltinBefore(const BuiltinType *T, raw_ostream &OS) {
+ OS << T->getName(Policy);
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) { }
-void TypePrinter::printPointer(const PointerType *T, std::string &S) {
- S = '*' + S;
-
+void TypePrinter::printComplexBefore(const ComplexType *T, raw_ostream &OS) {
+ OS << "_Complex ";
+ printBefore(T->getElementType(), OS);
+}
+void TypePrinter::printComplexAfter(const ComplexType *T, raw_ostream &OS) {
+ printAfter(T->getElementType(), OS);
+}
+
+void TypePrinter::printPointerBefore(const PointerType *T, raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getPointeeType(), OS);
// Handle things like 'int (*A)[4];' correctly.
// FIXME: this should include vectors, but vectors use attributes I guess.
if (isa<ArrayType>(T->getPointeeType()))
- S = '(' + S + ')';
-
+ OS << '(';
+ OS << '*';
+}
+void TypePrinter::printPointerAfter(const PointerType *T, raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getPointeeType(), S);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ // Handle things like 'int (*A)[4];' correctly.
+ // FIXME: this should include vectors, but vectors use attributes I guess.
+ if (isa<ArrayType>(T->getPointeeType()))
+ OS << ')';
+ printAfter(T->getPointeeType(), OS);
}
-void TypePrinter::printBlockPointer(const BlockPointerType *T, std::string &S) {
- S = '^' + S;
- print(T->getPointeeType(), S);
+void TypePrinter::printBlockPointerBefore(const BlockPointerType *T,
+ raw_ostream &OS) {
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getPointeeType(), OS);
+ OS << '^';
+}
+void TypePrinter::printBlockPointerAfter(const BlockPointerType *T,
+ raw_ostream &OS) {
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printAfter(T->getPointeeType(), OS);
}
-void TypePrinter::printLValueReference(const LValueReferenceType *T,
- std::string &S) {
- S = '&' + S;
-
+void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T,
+ raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getPointeeTypeAsWritten(), OS);
// Handle things like 'int (&A)[4];' correctly.
// FIXME: this should include vectors, but vectors use attributes I guess.
if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
- S = '(' + S + ')';
-
+ OS << '(';
+ OS << '&';
+}
+void TypePrinter::printLValueReferenceAfter(const LValueReferenceType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getPointeeTypeAsWritten(), S);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ // Handle things like 'int (&A)[4];' correctly.
+ // FIXME: this should include vectors, but vectors use attributes I guess.
+ if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
+ OS << ')';
+ printAfter(T->getPointeeTypeAsWritten(), OS);
}
-void TypePrinter::printRValueReference(const RValueReferenceType *T,
- std::string &S) {
- S = "&&" + S;
-
+void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T,
+ raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getPointeeTypeAsWritten(), OS);
// Handle things like 'int (&&A)[4];' correctly.
// FIXME: this should include vectors, but vectors use attributes I guess.
if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
- S = '(' + S + ')';
-
+ OS << '(';
+ OS << "&&";
+}
+void TypePrinter::printRValueReferenceAfter(const RValueReferenceType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getPointeeTypeAsWritten(), S);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ // Handle things like 'int (&&A)[4];' correctly.
+ // FIXME: this should include vectors, but vectors use attributes I guess.
+ if (isa<ArrayType>(T->getPointeeTypeAsWritten()))
+ OS << ')';
+ printAfter(T->getPointeeTypeAsWritten(), OS);
}
-void TypePrinter::printMemberPointer(const MemberPointerType *T,
- std::string &S) {
- PrintingPolicy InnerPolicy(Policy);
- Policy.SuppressTag = true;
- std::string C = QualType(T->getClass(), 0).getAsString(InnerPolicy);
- C += "::*";
- S = C + S;
-
+void TypePrinter::printMemberPointerBefore(const MemberPointerType *T,
+ raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getPointeeType(), OS);
// Handle things like 'int (Cls::*A)[4];' correctly.
// FIXME: this should include vectors, but vectors use attributes I guess.
if (isa<ArrayType>(T->getPointeeType()))
- S = '(' + S + ')';
-
+ OS << '(';
+
+ PrintingPolicy InnerPolicy(Policy);
+ InnerPolicy.SuppressTag = false;
+ TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
+
+ OS << "::*";
+}
+void TypePrinter::printMemberPointerAfter(const MemberPointerType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getPointeeType(), S);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ // Handle things like 'int (Cls::*A)[4];' correctly.
+ // FIXME: this should include vectors, but vectors use attributes I guess.
+ if (isa<ArrayType>(T->getPointeeType()))
+ OS << ')';
+ printAfter(T->getPointeeType(), OS);
}
-void TypePrinter::printConstantArray(const ConstantArrayType *T,
- std::string &S) {
- S += '[';
- S += llvm::utostr(T->getSize().getZExtValue());
- S += ']';
-
+void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getElementType(), S);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getElementType(), OS);
+}
+void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
+ raw_ostream &OS) {
+ OS << '[' << T->getSize().getZExtValue() << ']';
+ printAfter(T->getElementType(), OS);
}
-void TypePrinter::printIncompleteArray(const IncompleteArrayType *T,
- std::string &S) {
- S += "[]";
+void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getElementType(), S);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getElementType(), OS);
+}
+void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T,
+ raw_ostream &OS) {
+ OS << "[]";
+ printAfter(T->getElementType(), OS);
}
-void TypePrinter::printVariableArray(const VariableArrayType *T,
- std::string &S) {
- S += '[';
-
+void TypePrinter::printVariableArrayBefore(const VariableArrayType *T,
+ raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getElementType(), OS);
+}
+void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
+ raw_ostream &OS) {
+ OS << '[';
if (T->getIndexTypeQualifiers().hasQualifiers()) {
- AppendTypeQualList(S, T->getIndexTypeCVRQualifiers());
- S += ' ';
+ AppendTypeQualList(OS, T->getIndexTypeCVRQualifiers());
+ OS << ' ';
}
if (T->getSizeModifier() == VariableArrayType::Static)
- S += "static";
+ OS << "static";
else if (T->getSizeModifier() == VariableArrayType::Star)
- S += '*';
-
- if (T->getSizeExpr()) {
- std::string SStr;
- llvm::raw_string_ostream s(SStr);
- T->getSizeExpr()->printPretty(s, 0, Policy);
- S += s.str();
- }
- S += ']';
+ OS << '*';
- IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getElementType(), S);
+ if (T->getSizeExpr())
+ T->getSizeExpr()->printPretty(OS, 0, Policy);
+ OS << ']';
+
+ printAfter(T->getElementType(), OS);
}
-void TypePrinter::printDependentSizedArray(const DependentSizedArrayType *T,
- std::string &S) {
- S += '[';
-
- if (T->getSizeExpr()) {
- std::string SStr;
- llvm::raw_string_ostream s(SStr);
- T->getSizeExpr()->printPretty(s, 0, Policy);
- S += s.str();
- }
- S += ']';
-
+void TypePrinter::printDependentSizedArrayBefore(
+ const DependentSizedArrayType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getElementType(), S);
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+ printBefore(T->getElementType(), OS);
+}
+void TypePrinter::printDependentSizedArrayAfter(
+ const DependentSizedArrayType *T,
+ raw_ostream &OS) {
+ OS << '[';
+ if (T->getSizeExpr())
+ T->getSizeExpr()->printPretty(OS, 0, Policy);
+ OS << ']';
+ printAfter(T->getElementType(), OS);
}
-void TypePrinter::printDependentSizedExtVector(
+void TypePrinter::printDependentSizedExtVectorBefore(
const DependentSizedExtVectorType *T,
- std::string &S) {
- print(T->getElementType(), S);
-
- S += " __attribute__((ext_vector_type(";
- if (T->getSizeExpr()) {
- std::string SStr;
- llvm::raw_string_ostream s(SStr);
- T->getSizeExpr()->printPretty(s, 0, Policy);
- S += s.str();
- }
- S += ")))";
+ raw_ostream &OS) {
+ printBefore(T->getElementType(), OS);
+}
+void TypePrinter::printDependentSizedExtVectorAfter(
+ const DependentSizedExtVectorType *T,
+ raw_ostream &OS) {
+ OS << " __attribute__((ext_vector_type(";
+ if (T->getSizeExpr())
+ T->getSizeExpr()->printPretty(OS, 0, Policy);
+ OS << ")))";
+ printAfter(T->getElementType(), OS);
}
-void TypePrinter::printVector(const VectorType *T, std::string &S) {
+void TypePrinter::printVectorBefore(const VectorType *T, raw_ostream &OS) {
switch (T->getVectorKind()) {
case VectorType::AltiVecPixel:
- S = "__vector __pixel " + S;
+ OS << "__vector __pixel ";
break;
case VectorType::AltiVecBool:
- print(T->getElementType(), S);
- S = "__vector __bool " + S;
+ OS << "__vector __bool ";
+ printBefore(T->getElementType(), OS);
break;
case VectorType::AltiVecVector:
- print(T->getElementType(), S);
- S = "__vector " + S;
+ OS << "__vector ";
+ printBefore(T->getElementType(), OS);
break;
case VectorType::NeonVector:
- print(T->getElementType(), S);
- S = ("__attribute__((neon_vector_type(" +
- llvm::utostr_32(T->getNumElements()) + "))) " + S);
+ OS << "__attribute__((neon_vector_type("
+ << T->getNumElements() << "))) ";
+ printBefore(T->getElementType(), OS);
break;
case VectorType::NeonPolyVector:
- print(T->getElementType(), S);
- S = ("__attribute__((neon_polyvector_type(" +
- llvm::utostr_32(T->getNumElements()) + "))) " + S);
+ OS << "__attribute__((neon_polyvector_type(" <<
+ T->getNumElements() << "))) ";
+ printBefore(T->getElementType(), OS);
break;
case VectorType::GenericVector: {
// FIXME: We prefer to print the size directly here, but have no way
// to get the size of the type.
- print(T->getElementType(), S);
- std::string V = "__attribute__((__vector_size__(";
- V += llvm::utostr_32(T->getNumElements()); // convert back to bytes.
- std::string ET;
- print(T->getElementType(), ET);
- V += " * sizeof(" + ET + ")))) ";
- S = V + S;
+ OS << "__attribute__((__vector_size__("
+ << T->getNumElements()
+ << " * sizeof(";
+ print(T->getElementType(), OS, StringRef());
+ OS << ")))) ";
+ printBefore(T->getElementType(), OS);
break;
}
}
}
+void TypePrinter::printVectorAfter(const VectorType *T, raw_ostream &OS) {
+ printAfter(T->getElementType(), OS);
+}
-void TypePrinter::printExtVector(const ExtVectorType *T, std::string &S) {
- S += " __attribute__((ext_vector_type(";
- S += llvm::utostr_32(T->getNumElements());
- S += ")))";
- print(T->getElementType(), S);
+void TypePrinter::printExtVectorBefore(const ExtVectorType *T,
+ raw_ostream &OS) {
+ printBefore(T->getElementType(), OS);
+}
+void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream &OS) {
+ printAfter(T->getElementType(), OS);
+ OS << " __attribute__((ext_vector_type(";
+ OS << T->getNumElements();
+ OS << ")))";
}
void
-FunctionProtoType::printExceptionSpecification(std::string &S,
+FunctionProtoType::printExceptionSpecification(raw_ostream &OS,
PrintingPolicy Policy) const {
if (hasDynamicExceptionSpec()) {
- S += " throw(";
+ OS << " throw(";
if (getExceptionSpecType() == EST_MSAny)
- S += "...";
+ OS << "...";
else
for (unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
if (I)
- S += ", ";
+ OS << ", ";
- S += getExceptionType(I).getAsString(Policy);
+ OS << getExceptionType(I).stream(Policy);
}
- S += ")";
+ OS << ')';
} else if (isNoexceptExceptionSpec(getExceptionSpecType())) {
- S += " noexcept";
+ OS << " noexcept";
if (getExceptionSpecType() == EST_ComputedNoexcept) {
- S += "(";
- llvm::raw_string_ostream EOut(S);
- getNoexceptExpr()->printPretty(EOut, 0, Policy);
- EOut.flush();
- S += EOut.str();
- S += ")";
+ OS << '(';
+ getNoexceptExpr()->printPretty(OS, 0, Policy);
+ OS << ')';
}
}
}
-void TypePrinter::printFunctionProto(const FunctionProtoType *T,
- std::string &S) {
+void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T,
+ raw_ostream &OS) {
+ if (T->hasTrailingReturn()) {
+ OS << "auto ";
+ if (!HasEmptyPlaceHolder)
+ OS << '(';
+ } else {
+ // If needed for precedence reasons, wrap the inner part in grouping parens.
+ SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
+ printBefore(T->getResultType(), OS);
+ if (!PrevPHIsEmpty.get())
+ OS << '(';
+ }
+}
+
+void TypePrinter::printFunctionProtoAfter(const FunctionProtoType *T,
+ raw_ostream &OS) {
// If needed for precedence reasons, wrap the inner part in grouping parens.
- if (!S.empty())
- S = "(" + S + ")";
-
- S += "(";
- std::string Tmp;
- PrintingPolicy ParamPolicy(Policy);
- ParamPolicy.SuppressSpecifiers = false;
- for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
- if (i) S += ", ";
- print(T->getArgType(i), Tmp);
- S += Tmp;
- Tmp.clear();
+ if (!HasEmptyPlaceHolder)
+ OS << ')';
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
+
+ OS << '(';
+ {
+ ParamPolicyRAII ParamPolicy(Policy);
+ for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
+ if (i) OS << ", ";
+ print(T->getArgType(i), OS, StringRef());
+ }
}
if (T->isVariadic()) {
if (T->getNumArgs())
- S += ", ";
- S += "...";
+ OS << ", ";
+ OS << "...";
} else if (T->getNumArgs() == 0 && !Policy.LangOpts.CPlusPlus) {
// Do not emit int() if we have a proto, emit 'int(void)'.
- S += "void";
+ OS << "void";
}
- S += ")";
+ OS << ')';
FunctionType::ExtInfo Info = T->getExtInfo();
switch(Info.getCC()) {
case CC_Default: break;
case CC_C:
- S += " __attribute__((cdecl))";
+ OS << " __attribute__((cdecl))";
break;
case CC_X86StdCall:
- S += " __attribute__((stdcall))";
+ OS << " __attribute__((stdcall))";
break;
case CC_X86FastCall:
- S += " __attribute__((fastcall))";
+ OS << " __attribute__((fastcall))";
break;
case CC_X86ThisCall:
- S += " __attribute__((thiscall))";
+ OS << " __attribute__((thiscall))";
break;
case CC_X86Pascal:
- S += " __attribute__((pascal))";
+ OS << " __attribute__((pascal))";
break;
case CC_AAPCS:
- S += " __attribute__((pcs(\"aapcs\")))";
+ OS << " __attribute__((pcs(\"aapcs\")))";
break;
case CC_AAPCS_VFP:
- S += " __attribute__((pcs(\"aapcs-vfp\")))";
+ OS << " __attribute__((pcs(\"aapcs-vfp\")))";
break;
}
if (Info.getNoReturn())
- S += " __attribute__((noreturn))";
+ OS << " __attribute__((noreturn))";
if (Info.getRegParm())
- S += " __attribute__((regparm (" +
- llvm::utostr_32(Info.getRegParm()) + ")))";
-
- AppendTypeQualList(S, T->getTypeQuals());
+ OS << " __attribute__((regparm ("
+ << Info.getRegParm() << ")))";
+
+ if (unsigned quals = T->getTypeQuals()) {
+ OS << ' ';
+ AppendTypeQualList(OS, quals);
+ }
switch (T->getRefQualifier()) {
case RQ_None:
break;
case RQ_LValue:
- S += " &";
+ OS << " &";
break;
case RQ_RValue:
- S += " &&";
+ OS << " &&";
break;
}
- T->printExceptionSpecification(S, Policy);
+ T->printExceptionSpecification(OS, Policy);
+
if (T->hasTrailingReturn()) {
- std::string ResultS;
- print(T->getResultType(), ResultS);
- S = "auto " + S + " -> " + ResultS;
+ OS << " -> ";
+ print(T->getResultType(), OS, StringRef());
} else
- print(T->getResultType(), S);
+ printAfter(T->getResultType(), OS);
}
-void TypePrinter::printFunctionNoProto(const FunctionNoProtoType *T,
- std::string &S) {
+void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T,
+ raw_ostream &OS) {
// If needed for precedence reasons, wrap the inner part in grouping parens.
- if (!S.empty())
- S = "(" + S + ")";
+ SaveAndRestore<bool> PrevPHIsEmpty(HasEmptyPlaceHolder, false);
+ printBefore(T->getResultType(), OS);
+ if (!PrevPHIsEmpty.get())
+ OS << '(';
+}
+void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T,
+ raw_ostream &OS) {
+ // If needed for precedence reasons, wrap the inner part in grouping parens.
+ if (!HasEmptyPlaceHolder)
+ OS << ')';
+ SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
- S += "()";
+ OS << "()";
if (T->getNoReturnAttr())
- S += " __attribute__((noreturn))";
- print(T->getResultType(), S);
+ OS << " __attribute__((noreturn))";
+ printAfter(T->getResultType(), OS);
}
-static void printTypeSpec(const NamedDecl *D, std::string &S) {
+void TypePrinter::printTypeSpec(const NamedDecl *D, raw_ostream &OS) {
IdentifierInfo *II = D->getIdentifier();
- if (S.empty())
- S = II->getName().str();
- else
- S = II->getName().str() + ' ' + S;
+ OS << II->getName();
+ spaceBeforePlaceHolder(OS);
}
-void TypePrinter::printUnresolvedUsing(const UnresolvedUsingType *T,
- std::string &S) {
- printTypeSpec(T->getDecl(), S);
+void TypePrinter::printUnresolvedUsingBefore(const UnresolvedUsingType *T,
+ raw_ostream &OS) {
+ printTypeSpec(T->getDecl(), OS);
}
+void TypePrinter::printUnresolvedUsingAfter(const UnresolvedUsingType *T,
+ raw_ostream &OS) { }
-void TypePrinter::printTypedef(const TypedefType *T, std::string &S) {
- printTypeSpec(T->getDecl(), S);
+void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) {
+ printTypeSpec(T->getDecl(), OS);
}
+void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) { }
-void TypePrinter::printTypeOfExpr(const TypeOfExprType *T, std::string &S) {
- if (!S.empty()) // Prefix the basic type, e.g. 'typeof(e) X'.
- S = ' ' + S;
- std::string Str;
- llvm::raw_string_ostream s(Str);
- T->getUnderlyingExpr()->printPretty(s, 0, Policy);
- S = "typeof " + s.str() + S;
+void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,
+ raw_ostream &OS) {
+ OS << "typeof ";
+ T->getUnderlyingExpr()->printPretty(OS, 0, Policy);
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T,
+ raw_ostream &OS) { }
-void TypePrinter::printTypeOf(const TypeOfType *T, std::string &S) {
- if (!S.empty()) // Prefix the basic type, e.g. 'typeof(t) X'.
- S = ' ' + S;
- std::string Tmp;
- print(T->getUnderlyingType(), Tmp);
- S = "typeof(" + Tmp + ")" + S;
+void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) {
+ OS << "typeof(";
+ print(T->getUnderlyingType(), OS, StringRef());
+ OS << ')';
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) { }
-void TypePrinter::printDecltype(const DecltypeType *T, std::string &S) {
- if (!S.empty()) // Prefix the basic type, e.g. 'decltype(t) X'.
- S = ' ' + S;
- std::string Str;
- llvm::raw_string_ostream s(Str);
- T->getUnderlyingExpr()->printPretty(s, 0, Policy);
- S = "decltype(" + s.str() + ")" + S;
+void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) {
+ OS << "decltype(";
+ T->getUnderlyingExpr()->printPretty(OS, 0, Policy);
+ OS << ')';
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) { }
-void TypePrinter::printUnaryTransform(const UnaryTransformType *T,
- std::string &S) {
- if (!S.empty())
- S = ' ' + S;
- std::string Str;
+void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getBaseType(), Str);
switch (T->getUTTKind()) {
case UnaryTransformType::EnumUnderlyingType:
- S = "__underlying_type(" + Str + ")" + S;
- break;
+ OS << "__underlying_type(";
+ print(T->getBaseType(), OS, StringRef());
+ OS << ')';
+ spaceBeforePlaceHolder(OS);
+ return;
}
+
+ printBefore(T->getBaseType(), OS);
}
+void TypePrinter::printUnaryTransformAfter(const UnaryTransformType *T,
+ raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+
+ switch (T->getUTTKind()) {
+ case UnaryTransformType::EnumUnderlyingType:
+ return;
+ }
-void TypePrinter::printAuto(const AutoType *T, std::string &S) {
+ printAfter(T->getBaseType(), OS);
+}
+
+void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) {
// If the type has been deduced, do not print 'auto'.
if (T->isDeduced()) {
- print(T->getDeducedType(), S);
+ printBefore(T->getDeducedType(), OS);
} else {
- if (!S.empty()) // Prefix the basic type, e.g. 'auto X'.
- S = ' ' + S;
- S = "auto" + S;
+ OS << "auto";
+ spaceBeforePlaceHolder(OS);
}
}
+void TypePrinter::printAutoAfter(const AutoType *T, raw_ostream &OS) {
+ // If the type has been deduced, do not print 'auto'.
+ if (T->isDeduced())
+ printAfter(T->getDeducedType(), OS);
+}
-void TypePrinter::printAtomic(const AtomicType *T, std::string &S) {
- if (!S.empty())
- S = ' ' + S;
- std::string Str;
+void TypePrinter::printAtomicBefore(const AtomicType *T, raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getValueType(), Str);
- S = "_Atomic(" + Str + ")" + S;
+ OS << "_Atomic(";
+ print(T->getValueType(), OS, StringRef());
+ OS << ')';
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) { }
/// Appends the given scope to the end of a string.
-void TypePrinter::AppendScope(DeclContext *DC, std::string &Buffer) {
+void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) {
if (DC->isTranslationUnit()) return;
- AppendScope(DC->getParent(), Buffer);
-
- unsigned OldSize = Buffer.size();
+ AppendScope(DC->getParent(), OS);
if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) {
if (Policy.SuppressUnwrittenScope &&
(NS->isAnonymousNamespace() || NS->isInline()))
return;
if (NS->getIdentifier())
- Buffer += NS->getNameAsString();
+ OS << NS->getName() << "::";
else
- Buffer += "<anonymous>";
+ OS << "<anonymous>::";
} else if (ClassTemplateSpecializationDecl *Spec
= dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
IncludeStrongLifetimeRAII Strong(Policy);
+ OS << Spec->getIdentifier()->getName();
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
- std::string TemplateArgsStr
- = TemplateSpecializationType::PrintTemplateArgumentList(
+ TemplateSpecializationType::PrintTemplateArgumentList(OS,
TemplateArgs.data(),
TemplateArgs.size(),
Policy);
- Buffer += Spec->getIdentifier()->getName();
- Buffer += TemplateArgsStr;
+ OS << "::";
} else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl())
- Buffer += Typedef->getIdentifier()->getName();
+ OS << Typedef->getIdentifier()->getName() << "::";
else if (Tag->getIdentifier())
- Buffer += Tag->getIdentifier()->getName();
+ OS << Tag->getIdentifier()->getName() << "::";
else
return;
}
-
- if (Buffer.size() != OldSize)
- Buffer += "::";
}
-void TypePrinter::printTag(TagDecl *D, std::string &InnerString) {
+void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
if (Policy.SuppressTag)
return;
- std::string Buffer;
bool HasKindDecoration = false;
// bool SuppressTagKeyword
@@ -654,25 +833,24 @@
if (!(Policy.LangOpts.CPlusPlus || Policy.SuppressTagKeyword ||
D->getTypedefNameForAnonDecl())) {
HasKindDecoration = true;
- Buffer += D->getKindName();
- Buffer += ' ';
+ OS << D->getKindName();
+ OS << ' ';
}
// Compute the full nested-name-specifier for this type.
// In C, this will always be empty except when the type
// being printed is anonymous within other Record.
if (!Policy.SuppressScope)
- AppendScope(D->getDeclContext(), Buffer);
+ AppendScope(D->getDeclContext(), OS);
if (const IdentifierInfo *II = D->getIdentifier())
- Buffer += II->getNameStart();
+ OS << II->getName();
else if (TypedefNameDecl *Typedef = D->getTypedefNameForAnonDecl()) {
assert(Typedef->getIdentifier() && "Typedef without identifier?");
- Buffer += Typedef->getIdentifier()->getNameStart();
+ OS << Typedef->getIdentifier()->getName();
} else {
// Make an unambiguous representation for anonymous types, e.g.
// <anonymous enum at /usr/include/string.h:120:9>
- llvm::raw_string_ostream OS(Buffer);
if (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda()) {
OS << "<lambda";
@@ -717,219 +895,223 @@
NumArgs = TemplateArgs.size();
}
IncludeStrongLifetimeRAII Strong(Policy);
- Buffer += TemplateSpecializationType::PrintTemplateArgumentList(Args,
- NumArgs,
- Policy);
+ TemplateSpecializationType::PrintTemplateArgumentList(OS,
+ Args, NumArgs,
+ Policy);
}
- if (!InnerString.empty()) {
- Buffer += ' ';
- Buffer += InnerString;
- }
-
- std::swap(Buffer, InnerString);
+ spaceBeforePlaceHolder(OS);
}
-void TypePrinter::printRecord(const RecordType *T, std::string &S) {
- printTag(T->getDecl(), S);
+void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) {
+ printTag(T->getDecl(), OS);
}
+void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) { }
-void TypePrinter::printEnum(const EnumType *T, std::string &S) {
- printTag(T->getDecl(), S);
+void TypePrinter::printEnumBefore(const EnumType *T, raw_ostream &OS) {
+ printTag(T->getDecl(), OS);
}
+void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) { }
-void TypePrinter::printTemplateTypeParm(const TemplateTypeParmType *T,
- std::string &S) {
- if (!S.empty()) // Prefix the basic type, e.g. 'parmname X'.
- S = ' ' + S;
-
+void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T,
+ raw_ostream &OS) {
if (IdentifierInfo *Id = T->getIdentifier())
- S = Id->getName().str() + S;
+ OS << Id->getName();
else
- S = "type-parameter-" + llvm::utostr_32(T->getDepth()) + '-' +
- llvm::utostr_32(T->getIndex()) + S;
+ OS << "type-parameter-" << T->getDepth() << '-' << T->getIndex();
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printTemplateTypeParmAfter(const TemplateTypeParmType *T,
+ raw_ostream &OS) { }
-void TypePrinter::printSubstTemplateTypeParm(const SubstTemplateTypeParmType *T,
- std::string &S) {
+void TypePrinter::printSubstTemplateTypeParmBefore(
+ const SubstTemplateTypeParmType *T,
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- print(T->getReplacementType(), S);
+ printBefore(T->getReplacementType(), OS);
+}
+void TypePrinter::printSubstTemplateTypeParmAfter(
+ const SubstTemplateTypeParmType *T,
+ raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+ printAfter(T->getReplacementType(), OS);
}
-void TypePrinter::printSubstTemplateTypeParmPack(
+void TypePrinter::printSubstTemplateTypeParmPackBefore(
const SubstTemplateTypeParmPackType *T,
- std::string &S) {
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- printTemplateTypeParm(T->getReplacedParameter(), S);
+ printTemplateTypeParmBefore(T->getReplacedParameter(), OS);
+}
+void TypePrinter::printSubstTemplateTypeParmPackAfter(
+ const SubstTemplateTypeParmPackType *T,
+ raw_ostream &OS) {
+ IncludeStrongLifetimeRAII Strong(Policy);
+ printTemplateTypeParmAfter(T->getReplacedParameter(), OS);
}
-void TypePrinter::printTemplateSpecialization(
+void TypePrinter::printTemplateSpecializationBefore(
const TemplateSpecializationType *T,
- std::string &S) {
+ raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- std::string SpecString;
-
- {
- llvm::raw_string_ostream OS(SpecString);
- T->getTemplateName().print(OS, Policy);
- }
+ T->getTemplateName().print(OS, Policy);
- SpecString += TemplateSpecializationType::PrintTemplateArgumentList(
- T->getArgs(),
- T->getNumArgs(),
- Policy);
- if (S.empty())
- S.swap(SpecString);
- else
- S = SpecString + ' ' + S;
-}
-
-void TypePrinter::printInjectedClassName(const InjectedClassNameType *T,
- std::string &S) {
- printTemplateSpecialization(T->getInjectedTST(), S);
+ TemplateSpecializationType::PrintTemplateArgumentList(OS,
+ T->getArgs(),
+ T->getNumArgs(),
+ Policy);
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printTemplateSpecializationAfter(
+ const TemplateSpecializationType *T,
+ raw_ostream &OS) { }
-void TypePrinter::printElaborated(const ElaboratedType *T, std::string &S) {
- std::string MyString;
-
- {
- llvm::raw_string_ostream OS(MyString);
- OS << TypeWithKeyword::getKeywordName(T->getKeyword());
- if (T->getKeyword() != ETK_None)
- OS << " ";
- NestedNameSpecifier* Qualifier = T->getQualifier();
- if (Qualifier)
- Qualifier->print(OS, Policy);
- }
-
- std::string TypeStr;
- PrintingPolicy InnerPolicy(Policy);
- InnerPolicy.SuppressTagKeyword = true;
- InnerPolicy.SuppressScope = true;
- TypePrinter(InnerPolicy).print(T->getNamedType(), TypeStr);
-
- MyString += TypeStr;
- if (S.empty())
- S.swap(MyString);
- else
- S = MyString + ' ' + S;
+void TypePrinter::printInjectedClassNameBefore(const InjectedClassNameType *T,
+ raw_ostream &OS) {
+ printTemplateSpecializationBefore(T->getInjectedTST(), OS);
+}
+void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T,
+ raw_ostream &OS) { }
+
+void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
+ raw_ostream &OS) {
+ OS << TypeWithKeyword::getKeywordName(T->getKeyword());
+ if (T->getKeyword() != ETK_None)
+ OS << " ";
+ NestedNameSpecifier* Qualifier = T->getQualifier();
+ if (Qualifier)
+ Qualifier->print(OS, Policy);
+
+ ElaboratedTypePolicyRAII PolicyRAII(Policy);
+ printBefore(T->getNamedType(), OS);
+}
+void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
+ raw_ostream &OS) {
+ ElaboratedTypePolicyRAII PolicyRAII(Policy);
+ printAfter(T->getNamedType(), OS);
+}
+
+void TypePrinter::printParenBefore(const ParenType *T, raw_ostream &OS) {
+ if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
+ printBefore(T->getInnerType(), OS);
+ OS << '(';
+ } else
+ printBefore(T->getInnerType(), OS);
}
-
-void TypePrinter::printParen(const ParenType *T, std::string &S) {
- if (!S.empty() && !isa<FunctionType>(T->getInnerType()))
- S = '(' + S + ')';
- print(T->getInnerType(), S);
+void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) {
+ if (!HasEmptyPlaceHolder && !isa<FunctionType>(T->getInnerType())) {
+ OS << ')';
+ printAfter(T->getInnerType(), OS);
+ } else
+ printAfter(T->getInnerType(), OS);
}
-void TypePrinter::printDependentName(const DependentNameType *T, std::string &S) {
- std::string MyString;
+void TypePrinter::printDependentNameBefore(const DependentNameType *T,
+ raw_ostream &OS) {
+ OS << TypeWithKeyword::getKeywordName(T->getKeyword());
+ if (T->getKeyword() != ETK_None)
+ OS << " ";
- {
- llvm::raw_string_ostream OS(MyString);
- OS << TypeWithKeyword::getKeywordName(T->getKeyword());
- if (T->getKeyword() != ETK_None)
- OS << " ";
-
- T->getQualifier()->print(OS, Policy);
-
- OS << T->getIdentifier()->getName();
- }
+ T->getQualifier()->print(OS, Policy);
- if (S.empty())
- S.swap(MyString);
- else
- S = MyString + ' ' + S;
+ OS << T->getIdentifier()->getName();
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printDependentNameAfter(const DependentNameType *T,
+ raw_ostream &OS) { }
-void TypePrinter::printDependentTemplateSpecialization(
- const DependentTemplateSpecializationType *T, std::string &S) {
+void TypePrinter::printDependentTemplateSpecializationBefore(
+ const DependentTemplateSpecializationType *T, raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy);
- std::string MyString;
- {
- llvm::raw_string_ostream OS(MyString);
- OS << TypeWithKeyword::getKeywordName(T->getKeyword());
- if (T->getKeyword() != ETK_None)
- OS << " ";
-
- if (T->getQualifier())
- T->getQualifier()->print(OS, Policy);
- OS << T->getIdentifier()->getName();
- OS << TemplateSpecializationType::PrintTemplateArgumentList(
- T->getArgs(),
- T->getNumArgs(),
- Policy);
- }
-
- if (S.empty())
- S.swap(MyString);
- else
- S = MyString + ' ' + S;
+ OS << TypeWithKeyword::getKeywordName(T->getKeyword());
+ if (T->getKeyword() != ETK_None)
+ OS << " ";
+
+ if (T->getQualifier())
+ T->getQualifier()->print(OS, Policy);
+ OS << T->getIdentifier()->getName();
+ TemplateSpecializationType::PrintTemplateArgumentList(OS,
+ T->getArgs(),
+ T->getNumArgs(),
+ Policy);
+ spaceBeforePlaceHolder(OS);
+}
+void TypePrinter::printDependentTemplateSpecializationAfter(
+ const DependentTemplateSpecializationType *T, raw_ostream &OS) { }
+
+void TypePrinter::printPackExpansionBefore(const PackExpansionType *T,
+ raw_ostream &OS) {
+ printBefore(T->getPattern(), OS);
+}
+void TypePrinter::printPackExpansionAfter(const PackExpansionType *T,
+ raw_ostream &OS) {
+ printAfter(T->getPattern(), OS);
+ OS << "...";
}
-void TypePrinter::printPackExpansion(const PackExpansionType *T,
- std::string &S) {
- print(T->getPattern(), S);
- S += "...";
+void TypePrinter::printAttributedBefore(const AttributedType *T,
+ raw_ostream &OS) {
+ // Prefer the macro forms of the GC and ownership qualifiers.
+ if (T->getAttrKind() == AttributedType::attr_objc_gc ||
+ T->getAttrKind() == AttributedType::attr_objc_ownership)
+ return printBefore(T->getEquivalentType(), OS);
+
+ printBefore(T->getModifiedType(), OS);
}
-void TypePrinter::printAttributed(const AttributedType *T,
- std::string &S) {
+void TypePrinter::printAttributedAfter(const AttributedType *T,
+ raw_ostream &OS) {
// Prefer the macro forms of the GC and ownership qualifiers.
if (T->getAttrKind() == AttributedType::attr_objc_gc ||
T->getAttrKind() == AttributedType::attr_objc_ownership)
- return print(T->getEquivalentType(), S);
-
- print(T->getModifiedType(), S);
+ return printAfter(T->getEquivalentType(), OS);
// TODO: not all attributes are GCC-style attributes.
- S += " __attribute__((";
+ OS << " __attribute__((";
switch (T->getAttrKind()) {
case AttributedType::attr_address_space:
- S += "address_space(";
- S += T->getEquivalentType().getAddressSpace();
- S += ")";
+ OS << "address_space(";
+ OS << T->getEquivalentType().getAddressSpace();
+ OS << ')';
break;
case AttributedType::attr_vector_size: {
- S += "__vector_size__(";
+ OS << "__vector_size__(";
if (const VectorType *vector =T->getEquivalentType()->getAs<VectorType>()) {
- S += vector->getNumElements();
- S += " * sizeof(";
-
- std::string tmp;
- print(vector->getElementType(), tmp);
- S += tmp;
- S += ")";
+ OS << vector->getNumElements();
+ OS << " * sizeof(";
+ print(vector->getElementType(), OS, StringRef());
+ OS << ')';
}
- S += ")";
+ OS << ')';
break;
}
case AttributedType::attr_neon_vector_type:
case AttributedType::attr_neon_polyvector_type: {
if (T->getAttrKind() == AttributedType::attr_neon_vector_type)
- S += "neon_vector_type(";
+ OS << "neon_vector_type(";
else
- S += "neon_polyvector_type(";
+ OS << "neon_polyvector_type(";
const VectorType *vector = T->getEquivalentType()->getAs<VectorType>();
- S += llvm::utostr_32(vector->getNumElements());
- S += ")";
+ OS << vector->getNumElements();
+ OS << ')';
break;
}
case AttributedType::attr_regparm: {
- S += "regparm(";
+ OS << "regparm(";
QualType t = T->getEquivalentType();
while (!t->isFunctionType())
t = t->getPointeeType();
- S += t->getAs<FunctionType>()->getRegParmType();
- S += ")";
+ OS << t->getAs<FunctionType>()->getRegParmType();
+ OS << ')';
break;
}
case AttributedType::attr_objc_gc: {
- S += "objc_gc(";
+ OS << "objc_gc(";
QualType tmp = T->getEquivalentType();
while (tmp.getObjCGCAttr() == Qualifiers::GCNone) {
@@ -939,116 +1121,225 @@
}
if (tmp.isObjCGCWeak())
- S += "weak";
+ OS << "weak";
else
- S += "strong";
- S += ")";
+ OS << "strong";
+ OS << ')';
break;
}
case AttributedType::attr_objc_ownership:
- S += "objc_ownership(";
+ OS << "objc_ownership(";
switch (T->getEquivalentType().getObjCLifetime()) {
case Qualifiers::OCL_None: llvm_unreachable("no ownership!");
- case Qualifiers::OCL_ExplicitNone: S += "none"; break;
- case Qualifiers::OCL_Strong: S += "strong"; break;
- case Qualifiers::OCL_Weak: S += "weak"; break;
- case Qualifiers::OCL_Autoreleasing: S += "autoreleasing"; break;
+ case Qualifiers::OCL_ExplicitNone: OS << "none"; break;
+ case Qualifiers::OCL_Strong: OS << "strong"; break;
+ case Qualifiers::OCL_Weak: OS << "weak"; break;
+ case Qualifiers::OCL_Autoreleasing: OS << "autoreleasing"; break;
}
- S += ")";
+ OS << ')';
break;
- case AttributedType::attr_noreturn: S += "noreturn"; break;
- case AttributedType::attr_cdecl: S += "cdecl"; break;
- case AttributedType::attr_fastcall: S += "fastcall"; break;
- case AttributedType::attr_stdcall: S += "stdcall"; break;
- case AttributedType::attr_thiscall: S += "thiscall"; break;
- case AttributedType::attr_pascal: S += "pascal"; break;
+ case AttributedType::attr_noreturn: OS << "noreturn"; break;
+ case AttributedType::attr_cdecl: OS << "cdecl"; break;
+ case AttributedType::attr_fastcall: OS << "fastcall"; break;
+ case AttributedType::attr_stdcall: OS << "stdcall"; break;
+ case AttributedType::attr_thiscall: OS << "thiscall"; break;
+ case AttributedType::attr_pascal: OS << "pascal"; break;
case AttributedType::attr_pcs: {
- S += "pcs(";
+ OS << "pcs(";
QualType t = T->getEquivalentType();
while (!t->isFunctionType())
t = t->getPointeeType();
- S += (t->getAs<FunctionType>()->getCallConv() == CC_AAPCS ?
+ OS << (t->getAs<FunctionType>()->getCallConv() == CC_AAPCS ?
"\"aapcs\"" : "\"aapcs-vfp\"");
- S += ")";
+ OS << ')';
break;
}
}
- S += "))";
+ OS << "))";
}
-void TypePrinter::printObjCInterface(const ObjCInterfaceType *T,
- std::string &S) {
- if (!S.empty()) // Prefix the basic type, e.g. 'typedefname X'.
- S = ' ' + S;
-
- std::string ObjCQIString = T->getDecl()->getNameAsString();
- S = ObjCQIString + S;
+void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,
+ raw_ostream &OS) {
+ OS << T->getDecl()->getName();
+ spaceBeforePlaceHolder(OS);
}
+void TypePrinter::printObjCInterfaceAfter(const ObjCInterfaceType *T,
+ raw_ostream &OS) { }
-void TypePrinter::printObjCObject(const ObjCObjectType *T,
- std::string &S) {
+void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T,
+ raw_ostream &OS) {
if (T->qual_empty())
- return print(T->getBaseType(), S);
+ return printBefore(T->getBaseType(), OS);
- std::string tmp;
- print(T->getBaseType(), tmp);
- tmp += '<';
+ print(T->getBaseType(), OS, StringRef());
+ OS << '<';
bool isFirst = true;
for (ObjCObjectType::qual_iterator
I = T->qual_begin(), E = T->qual_end(); I != E; ++I) {
if (isFirst)
isFirst = false;
else
- tmp += ',';
- tmp += (*I)->getNameAsString();
+ OS << ',';
+ OS << (*I)->getName();
}
- tmp += '>';
-
- if (!S.empty()) {
- tmp += ' ';
- tmp += S;
- }
- std::swap(tmp, S);
+ OS << '>';
+ spaceBeforePlaceHolder(OS);
+}
+void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T,
+ raw_ostream &OS) {
+ if (T->qual_empty())
+ return printAfter(T->getBaseType(), OS);
}
-void TypePrinter::printObjCObjectPointer(const ObjCObjectPointerType *T,
- std::string &S) {
- std::string ObjCQIString;
-
- T->getPointeeType().getLocalQualifiers().getAsStringInternal(ObjCQIString,
- Policy);
- if (!ObjCQIString.empty())
- ObjCQIString += ' ';
-
+void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T,
+ raw_ostream &OS) {
+ T->getPointeeType().getLocalQualifiers().print(OS, Policy,
+ /*appendSpaceIfNonEmpty=*/true);
+
if (T->isObjCIdType() || T->isObjCQualifiedIdType())
- ObjCQIString += "id";
+ OS << "id";
else if (T->isObjCClassType() || T->isObjCQualifiedClassType())
- ObjCQIString += "Class";
+ OS << "Class";
else if (T->isObjCSelType())
- ObjCQIString += "SEL";
+ OS << "SEL";
else
- ObjCQIString += T->getInterfaceDecl()->getNameAsString();
+ OS << T->getInterfaceDecl()->getName();
if (!T->qual_empty()) {
- ObjCQIString += '<';
+ OS << '<';
for (ObjCObjectPointerType::qual_iterator I = T->qual_begin(),
E = T->qual_end();
I != E; ++I) {
- ObjCQIString += (*I)->getNameAsString();
+ OS << (*I)->getName();
if (I+1 != E)
- ObjCQIString += ',';
+ OS << ',';
}
- ObjCQIString += '>';
+ OS << '>';
}
- if (!T->isObjCIdType() && !T->isObjCQualifiedIdType())
- ObjCQIString += " *"; // Don't forget the implicit pointer.
- else if (!S.empty()) // Prefix the basic type, e.g. 'typedefname X'.
- S = ' ' + S;
+ if (!T->isObjCIdType() && !T->isObjCQualifiedIdType()) {
+ OS << " *"; // Don't forget the implicit pointer.
+ } else {
+ spaceBeforePlaceHolder(OS);
+ }
+}
+void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T,
+ raw_ostream &OS) { }
+
+void TemplateSpecializationType::
+ PrintTemplateArgumentList(raw_ostream &OS,
+ const TemplateArgumentListInfo &Args,
+ const PrintingPolicy &Policy) {
+ return PrintTemplateArgumentList(OS,
+ Args.getArgumentArray(),
+ Args.size(),
+ Policy);
+}
+
+void
+TemplateSpecializationType::PrintTemplateArgumentList(
+ raw_ostream &OS,
+ const TemplateArgument *Args,
+ unsigned NumArgs,
+ const PrintingPolicy &Policy,
+ bool SkipBrackets) {
+ if (!SkipBrackets)
+ OS << '<';
- S = ObjCQIString + S;
+ for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
+ if (Arg > 0)
+ OS << ", ";
+
+ // Print the argument into a string.
+ SmallString<128> Buf;
+ llvm::raw_svector_ostream ArgOS(Buf);
+ if (Args[Arg].getKind() == TemplateArgument::Pack) {
+ PrintTemplateArgumentList(ArgOS,
+ Args[Arg].pack_begin(),
+ Args[Arg].pack_size(),
+ Policy, true);
+ } else {
+ Args[Arg].print(Policy, ArgOS);
+ }
+ StringRef ArgString = ArgOS.str();
+
+ // If this is the first argument and its string representation
+ // begins with the global scope specifier ('::foo'), add a space
+ // to avoid printing the diagraph '<:'.
+ if (!Arg && !ArgString.empty() && ArgString[0] == ':')
+ OS << ' ';
+
+ OS << ArgString;
+ }
+
+ if (!SkipBrackets)
+ OS << '>';
+}
+
+// Sadly, repeat all that with TemplateArgLoc.
+void TemplateSpecializationType::
+PrintTemplateArgumentList(raw_ostream &OS,
+ const TemplateArgumentLoc *Args, unsigned NumArgs,
+ const PrintingPolicy &Policy) {
+ OS << '<';
+ for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
+ if (Arg > 0)
+ OS << ", ";
+
+ // Print the argument into a string.
+ SmallString<128> Buf;
+ llvm::raw_svector_ostream ArgOS(Buf);
+ if (Args[Arg].getArgument().getKind() == TemplateArgument::Pack) {
+ PrintTemplateArgumentList(ArgOS,
+ Args[Arg].getArgument().pack_begin(),
+ Args[Arg].getArgument().pack_size(),
+ Policy, true);
+ } else {
+ Args[Arg].getArgument().print(Policy, ArgOS);
+ }
+ StringRef ArgString = ArgOS.str();
+
+ // If this is the first argument and its string representation
+ // begins with the global scope specifier ('::foo'), add a space
+ // to avoid printing the diagraph '<:'.
+ if (!Arg && !ArgString.empty() && ArgString[0] == ':')
+ OS << ' ';
+
+ OS << ArgString;
+ }
+
+ OS << '>';
+}
+
+void
+FunctionProtoType::printExceptionSpecification(std::string &S,
+ PrintingPolicy Policy) const {
+
+ if (hasDynamicExceptionSpec()) {
+ S += " throw(";
+ if (getExceptionSpecType() == EST_MSAny)
+ S += "...";
+ else
+ for (unsigned I = 0, N = getNumExceptions(); I != N; ++I) {
+ if (I)
+ S += ", ";
+
+ S += getExceptionType(I).getAsString(Policy);
+ }
+ S += ")";
+ } else if (isNoexceptExceptionSpec(getExceptionSpecType())) {
+ S += " noexcept";
+ if (getExceptionSpecType() == EST_ComputedNoexcept) {
+ S += "(";
+ llvm::raw_string_ostream EOut(S);
+ getNoexceptExpr()->printPretty(EOut, 0, Policy);
+ EOut.flush();
+ S += EOut.str();
+ S += ")";
+ }
+ }
}
std::string TemplateSpecializationType::
@@ -1148,15 +1439,14 @@
}
void QualType::dump(const char *msg) const {
- std::string R = "identifier";
- LangOptions LO;
- getAsStringInternal(R, PrintingPolicy(LO));
if (msg)
llvm::errs() << msg << ": ";
- llvm::errs() << R << "\n";
+ LangOptions LO;
+ print(llvm::errs(), PrintingPolicy(LO), "identifier");
+ llvm::errs() << '\n';
}
void QualType::dump() const {
- dump("");
+ dump(0);
}
void Type::dump() const {
@@ -1171,51 +1461,99 @@
// Appends qualifiers to the given string, separated by spaces. Will
// prefix a space if the string is non-empty. Will not append a final
// space.
-void Qualifiers::getAsStringInternal(std::string &S,
- const PrintingPolicy& Policy) const {
- AppendTypeQualList(S, getCVRQualifiers());
+std::string Qualifiers::getAsString(const PrintingPolicy &Policy) const {
+ SmallString<64> Buf;
+ llvm::raw_svector_ostream StrOS(Buf);
+ print(StrOS, Policy);
+ return StrOS.str();
+}
+
+bool Qualifiers::isEmptyWhenPrinted(const PrintingPolicy &Policy) const {
+ if (getCVRQualifiers())
+ return false;
+
+ if (getAddressSpace())
+ return false;
+
+ if (getObjCGCAttr())
+ return false;
+
+ if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime())
+ if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime))
+ return false;
+
+ return true;
+}
+
+// Appends qualifiers to the given string, separated by spaces. Will
+// prefix a space if the string is non-empty. Will not append a final
+// space.
+void Qualifiers::print(raw_ostream &OS, const PrintingPolicy& Policy,
+ bool appendSpaceIfNonEmpty) const {
+ bool addSpace = false;
+
+ unsigned quals = getCVRQualifiers();
+ if (quals) {
+ AppendTypeQualList(OS, quals);
+ addSpace = true;
+ }
if (unsigned addrspace = getAddressSpace()) {
- if (!S.empty()) S += ' ';
+ if (addSpace)
+ OS << ' ';
+ addSpace = true;
switch (addrspace) {
case LangAS::opencl_global:
- S += "__global";
+ OS << "__global";
break;
case LangAS::opencl_local:
- S += "__local";
+ OS << "__local";
break;
case LangAS::opencl_constant:
- S += "__constant";
+ OS << "__constant";
break;
default:
- S += "__attribute__((address_space(";
- S += llvm::utostr_32(addrspace);
- S += ")))";
+ OS << "__attribute__((address_space(";
+ OS << addrspace;
+ OS << ")))";
}
}
if (Qualifiers::GC gc = getObjCGCAttr()) {
- if (!S.empty()) S += ' ';
+ if (addSpace)
+ OS << ' ';
+ addSpace = true;
if (gc == Qualifiers::Weak)
- S += "__weak";
+ OS << "__weak";
else
- S += "__strong";
+ OS << "__strong";
}
if (Qualifiers::ObjCLifetime lifetime = getObjCLifetime()) {
- if (!S.empty() &&
- !(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime))
- S += ' ';
+ if (!(lifetime == Qualifiers::OCL_Strong && Policy.SuppressStrongLifetime)){
+ if (addSpace)
+ OS << ' ';
+ addSpace = true;
+ }
switch (lifetime) {
case Qualifiers::OCL_None: llvm_unreachable("none but true");
- case Qualifiers::OCL_ExplicitNone: S += "__unsafe_unretained"; break;
+ case Qualifiers::OCL_ExplicitNone: OS << "__unsafe_unretained"; break;
case Qualifiers::OCL_Strong:
if (!Policy.SuppressStrongLifetime)
- S += "__strong";
+ OS << "__strong";
break;
- case Qualifiers::OCL_Weak: S += "__weak"; break;
- case Qualifiers::OCL_Autoreleasing: S += "__autoreleasing"; break;
+ case Qualifiers::OCL_Weak: OS << "__weak"; break;
+ case Qualifiers::OCL_Autoreleasing: OS << "__autoreleasing"; break;
}
}
+
+ if (appendSpaceIfNonEmpty && addSpace)
+ OS << ' ';
+}
+
+std::string QualType::getAsString(const PrintingPolicy &Policy) const {
+ std::string S;
+ getAsStringInternal(S, Policy);
+ return S;
}
std::string QualType::getAsString(const Type *ty, Qualifiers qs) {
@@ -1225,8 +1563,25 @@
return buffer;
}
+void QualType::print(const Type *ty, Qualifiers qs,
+ raw_ostream &OS, const PrintingPolicy &policy,
+ const Twine &PlaceHolder) {
+ SmallString<128> PHBuf;
+ StringRef PH;
+ if (PlaceHolder.isSingleStringRef())
+ PH = PlaceHolder.getSingleStringRef();
+ else
+ PH = PlaceHolder.toStringRef(PHBuf);
+
+ TypePrinter(policy).print(ty, qs, OS, PH);
+}
+
void QualType::getAsStringInternal(const Type *ty, Qualifiers qs,
std::string &buffer,
const PrintingPolicy &policy) {
- TypePrinter(policy).print(ty, qs, buffer);
+ SmallString<256> Buf;
+ llvm::raw_svector_ostream StrOS(Buf);
+ TypePrinter(policy).print(ty, qs, StrOS, buffer);
+ std::string str = StrOS.str();
+ buffer.swap(str);
}
Modified: cfe/branches/tooling/lib/AST/VTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/AST/VTableBuilder.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/AST/VTableBuilder.cpp (original)
+++ cfe/branches/tooling/lib/AST/VTableBuilder.cpp Tue May 8 03:47:31 2012
@@ -409,7 +409,7 @@
// Now dump the overriders for this base subobject.
for (CXXRecordDecl::method_iterator I = RD->method_begin(),
E = RD->method_end(); I != E; ++I) {
- const CXXMethodDecl *MD = *I;
+ const CXXMethodDecl *MD = &*I;
if (!MD->isVirtual())
continue;
@@ -692,7 +692,7 @@
// Add the vcall offsets.
for (CXXRecordDecl::method_iterator I = RD->method_begin(),
E = RD->method_end(); I != E; ++I) {
- const CXXMethodDecl *MD = *I;
+ const CXXMethodDecl *MD = &*I;
if (!MD->isVirtual())
continue;
@@ -1469,7 +1469,7 @@
// Now go through all virtual member functions and add them.
for (CXXRecordDecl::method_iterator I = RD->method_begin(),
E = RD->method_end(); I != E; ++I) {
- const CXXMethodDecl *MD = *I;
+ const CXXMethodDecl *MD = &*I;
if (!MD->isVirtual())
continue;
@@ -2105,7 +2105,7 @@
for (CXXRecordDecl::method_iterator i = MostDerivedClass->method_begin(),
e = MostDerivedClass->method_end(); i != e; ++i) {
- const CXXMethodDecl *MD = *i;
+ const CXXMethodDecl *MD = &*i;
// We only want virtual member functions.
if (!MD->isVirtual())
@@ -2217,7 +2217,7 @@
for (CXXRecordDecl::method_iterator i = RD->method_begin(),
e = RD->method_end(); i != e; ++i) {
- const CXXMethodDecl *MD = *i;
+ const CXXMethodDecl *MD = &*i;
// We only want virtual methods.
if (!MD->isVirtual())
Modified: cfe/branches/tooling/lib/Analysis/AnalysisDeclContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Analysis/AnalysisDeclContext.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Analysis/AnalysisDeclContext.cpp (original)
+++ cfe/branches/tooling/lib/Analysis/AnalysisDeclContext.cpp Tue May 8 03:47:31 2012
@@ -34,11 +34,9 @@
AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
const Decl *d,
- idx::TranslationUnit *tu,
const CFG::BuildOptions &buildOptions)
: Manager(Mgr),
D(d),
- TU(tu),
cfgBuildOptions(buildOptions),
forcedBlkExprs(0),
builtCFG(false),
@@ -50,11 +48,9 @@
}
AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
- const Decl *d,
- idx::TranslationUnit *tu)
+ const Decl *d)
: Manager(Mgr),
D(d),
- TU(tu),
forcedBlkExprs(0),
builtCFG(false),
builtCompleteCFG(false),
@@ -195,11 +191,10 @@
return PCA.get();
}
-AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D,
- idx::TranslationUnit *TU) {
+AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) {
AnalysisDeclContext *&AC = Contexts[D];
if (!AC)
- AC = new AnalysisDeclContext(this, D, TU, cfgBuildOptions);
+ AC = new AnalysisDeclContext(this, D, cfgBuildOptions);
return AC;
}
Modified: cfe/branches/tooling/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Analysis/CFG.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Analysis/CFG.cpp (original)
+++ cfe/branches/tooling/lib/Analysis/CFG.cpp Tue May 8 03:47:31 2012
@@ -832,7 +832,7 @@
if (const CXXRecordDecl *CD = QT->getAsCXXRecordDecl())
if (!CD->hasTrivialDestructor()) {
autoCreateBlock();
- appendMemberDtor(Block, *FI);
+ appendMemberDtor(Block, &*FI);
}
}
}
@@ -1070,9 +1070,6 @@
case Stmt::LambdaExprClass:
return VisitLambdaExpr(cast<LambdaExpr>(S), asc);
- case Stmt::AttributedStmtClass:
- return Visit(cast<AttributedStmt>(S)->getSubStmt(), asc);
-
case Stmt::MemberExprClass:
return VisitMemberExpr(cast<MemberExpr>(S), asc);
Modified: cfe/branches/tooling/lib/Analysis/FormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Analysis/FormatString.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Analysis/FormatString.cpp (original)
+++ cfe/branches/tooling/lib/Analysis/FormatString.cpp Tue May 8 03:47:31 2012
@@ -319,20 +319,21 @@
}
case WIntTy: {
- // Instead of doing a lookup for the definition of 'wint_t' (which
- // is defined by the system headers) instead see if wchar_t and
- // the argument type promote to the same type.
- QualType PromoWChar =
- C.getWCharType()->isPromotableIntegerType()
- ? C.getPromotedIntegerType(C.getWCharType()) : C.getWCharType();
+
QualType PromoArg =
argTy->isPromotableIntegerType()
? C.getPromotedIntegerType(argTy) : argTy;
- PromoWChar = C.getCanonicalType(PromoWChar).getUnqualifiedType();
+ QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType();
- return PromoWChar == PromoArg;
+ // If the promoted argument is the corresponding signed type of the
+ // wint_t type, then it should match.
+ if (PromoArg->hasSignedIntegerRepresentation() &&
+ C.getCorrespondingUnsignedType(PromoArg) == WInt)
+ return true;
+
+ return WInt == PromoArg;
}
case CPointerTy:
@@ -380,8 +381,7 @@
case CPointerTy:
return C.VoidPtrTy;
case WIntTy: {
- QualType WC = C.getWCharType();
- return WC->isPromotableIntegerType() ? C.getPromotedIntegerType(WC) : WC;
+ return C.getWIntType();
}
}
Modified: cfe/branches/tooling/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Analysis/UninitializedValues.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/branches/tooling/lib/Analysis/UninitializedValues.cpp Tue May 8 03:47:31 2012
@@ -61,7 +61,7 @@
DeclContext::specific_decl_iterator<VarDecl> I(dc.decls_begin()),
E(dc.decls_end());
for ( ; I != E; ++I) {
- const VarDecl *vd = *I;
+ const VarDecl *vd = &*I;
if (isTrackedVar(vd, &dc))
map[vd] = count++;
}
@@ -168,7 +168,8 @@
if (block->empty())
return 0;
- const CFGStmt *cstmt = block->front().getAs<CFGStmt>();
+ CFGElement front = block->front();
+ const CFGStmt *cstmt = front.getAs<CFGStmt>();
if (!cstmt)
return 0;
Modified: cfe/branches/tooling/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Basic/FileManager.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Basic/FileManager.cpp (original)
+++ cfe/branches/tooling/lib/Basic/FileManager.cpp Tue May 8 03:47:31 2012
@@ -584,6 +584,12 @@
UIDToFiles[(*VFE)->getUID()] = *VFE;
}
+void FileManager::modifyFileEntry(FileEntry *File,
+ off_t Size, time_t ModificationTime) {
+ File->Size = Size;
+ File->ModTime = ModificationTime;
+}
+
void FileManager::PrintStats() const {
llvm::errs() << "\n*** File Manager Stats:\n";
Modified: cfe/branches/tooling/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Basic/IdentifierTable.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/branches/tooling/lib/Basic/IdentifierTable.cpp Tue May 8 03:47:31 2012
@@ -335,22 +335,22 @@
unsigned Selector::getNumArgs() const {
unsigned IIF = getIdentifierInfoFlag();
- if (IIF == ZeroArg)
+ if (IIF <= ZeroArg)
return 0;
if (IIF == OneArg)
return 1;
- // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
- MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
+ // We point to a MultiKeywordSelector.
+ MultiKeywordSelector *SI = getMultiKeywordSelector();
return SI->getNumArgs();
}
IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
- if (getIdentifierInfoFlag()) {
+ if (getIdentifierInfoFlag() < MultiArg) {
assert(argIndex == 0 && "illegal keyword index");
return getAsIdentifierInfo();
}
- // We point to a MultiKeywordSelector (pointer doesn't contain any flags).
- MultiKeywordSelector *SI = reinterpret_cast<MultiKeywordSelector *>(InfoPtr);
+ // We point to a MultiKeywordSelector.
+ MultiKeywordSelector *SI = getMultiKeywordSelector();
return SI->getIdentifierInfoForSlot(argIndex);
}
@@ -375,7 +375,7 @@
if (InfoPtr == 0)
return "<null selector>";
- if (InfoPtr & ArgFlags) {
+ if (getIdentifierInfoFlag() < MultiArg) {
IdentifierInfo *II = getAsIdentifierInfo();
// If the number of arguments is 0 then II is guaranteed to not be null.
@@ -388,8 +388,8 @@
return II->getName().str() + ":";
}
- // We have a multiple keyword selector (no embedded flags).
- return reinterpret_cast<MultiKeywordSelector *>(InfoPtr)->getName();
+ // We have a multiple keyword selector.
+ return getMultiKeywordSelector()->getName();
}
/// Interpreting the given string using the normal CamelCase
Modified: cfe/branches/tooling/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Basic/SourceManager.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Basic/SourceManager.cpp (original)
+++ cfe/branches/tooling/lib/Basic/SourceManager.cpp Tue May 8 03:47:31 2012
@@ -71,7 +71,7 @@
void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B,
bool DoNotFree) {
- if (B == Buffer.getPointer()) {
+ if (B && B == Buffer.getPointer()) {
assert(0 && "Replacing with the same buffer");
Buffer.setInt(DoNotFree? DoNotFreeFlag : 0);
return;
@@ -440,16 +440,20 @@
EntryAlign = std::max(8U, EntryAlign);
Entry = ContentCacheAlloc.Allocate<ContentCache>(1, EntryAlign);
- // If the file contents are overridden with contents from another file,
- // pass that file to ContentCache.
- llvm::DenseMap<const FileEntry *, const FileEntry *>::iterator
- overI = OverriddenFiles.find(FileEnt);
- if (overI == OverriddenFiles.end())
+ if (OverriddenFilesInfo) {
+ // If the file contents are overridden with contents from another file,
+ // pass that file to ContentCache.
+ llvm::DenseMap<const FileEntry *, const FileEntry *>::iterator
+ overI = OverriddenFilesInfo->OverriddenFiles.find(FileEnt);
+ if (overI == OverriddenFilesInfo->OverriddenFiles.end())
+ new (Entry) ContentCache(FileEnt);
+ else
+ new (Entry) ContentCache(OverridenFilesKeepOriginalName ? FileEnt
+ : overI->second,
+ overI->second);
+ } else {
new (Entry) ContentCache(FileEnt);
- else
- new (Entry) ContentCache(OverridenFilesKeepOriginalName ? FileEnt
- : overI->second,
- overI->second);
+ }
return Entry;
}
@@ -622,6 +626,8 @@
const_cast<SrcMgr::ContentCache *>(IR)->replaceBuffer(Buffer, DoNotFree);
const_cast<SrcMgr::ContentCache *>(IR)->BufferOverridden = true;
+
+ getOverriddenFilesInfo().OverriddenFilesWithBuffer.insert(SourceFile);
}
void SourceManager::overrideFileContents(const FileEntry *SourceFile,
@@ -632,7 +638,20 @@
assert(FileInfos.count(SourceFile) == 0 &&
"This function should be called at the initialization stage, before "
"any parsing occurs.");
- OverriddenFiles[SourceFile] = NewFile;
+ getOverriddenFilesInfo().OverriddenFiles[SourceFile] = NewFile;
+}
+
+void SourceManager::disableFileContentsOverride(const FileEntry *File) {
+ if (!isFileOverridden(File))
+ return;
+
+ const SrcMgr::ContentCache *IR = getOrCreateContentCache(File);
+ const_cast<SrcMgr::ContentCache *>(IR)->replaceBuffer(0);
+ const_cast<SrcMgr::ContentCache *>(IR)->ContentsEntry = IR->OrigEntry;
+
+ assert(OverriddenFilesInfo);
+ OverriddenFilesInfo->OverriddenFiles.erase(File);
+ OverriddenFilesInfo->OverriddenFilesWithBuffer.erase(File);
}
StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
@@ -1887,10 +1906,14 @@
}
size_t SourceManager::getDataStructureSizes() const {
- return llvm::capacity_in_bytes(MemBufferInfos)
+ size_t size = llvm::capacity_in_bytes(MemBufferInfos)
+ llvm::capacity_in_bytes(LocalSLocEntryTable)
+ llvm::capacity_in_bytes(LoadedSLocEntryTable)
+ llvm::capacity_in_bytes(SLocEntryLoaded)
- + llvm::capacity_in_bytes(FileInfos)
- + llvm::capacity_in_bytes(OverriddenFiles);
+ + llvm::capacity_in_bytes(FileInfos);
+
+ if (OverriddenFilesInfo)
+ size += llvm::capacity_in_bytes(OverriddenFilesInfo->OverriddenFiles);
+
+ return size;
}
Modified: cfe/branches/tooling/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Basic/Targets.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Basic/Targets.cpp (original)
+++ cfe/branches/tooling/lib/Basic/Targets.cpp Tue May 8 03:47:31 2012
@@ -1699,7 +1699,7 @@
setFeatureEnabled(Features, "sse4a", true);
case CK_BDVER1:
case CK_BDVER2:
- setFeatureEnabled(Features, "sse4", true);
+ setFeatureEnabled(Features, "avx", true);
setFeatureEnabled(Features, "sse4a", true);
setFeatureEnabled(Features, "aes", true);
break;
Modified: cfe/branches/tooling/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/BackendUtil.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/BackendUtil.cpp Tue May 8 03:47:31 2012
@@ -219,7 +219,7 @@
CodeGenOpts.EmitGcovArcs,
TargetTriple.isMacOSX()));
- if (!CodeGenOpts.DebugInfo)
+ if (CodeGenOpts.DebugInfo == CodeGenOptions::NoDebugInfo)
MPM->add(createStripSymbolsPass(true));
}
Modified: cfe/branches/tooling/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGBlocks.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGBlocks.cpp Tue May 8 03:47:31 2012
@@ -458,19 +458,23 @@
}
}
+ assert(endAlign == getLowBit(blockSize));
+
// At this point, we just have to add padding if the end align still
// isn't aligned right.
if (endAlign < maxFieldAlign) {
- CharUnits padding = maxFieldAlign - endAlign;
+ CharUnits newBlockSize = blockSize.RoundUpToAlignment(maxFieldAlign);
+ CharUnits padding = newBlockSize - blockSize;
elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty,
padding.getQuantity()));
- blockSize += padding;
-
- endAlign = getLowBit(blockSize);
- assert(endAlign >= maxFieldAlign);
+ blockSize = newBlockSize;
+ endAlign = getLowBit(blockSize); // might be > maxFieldAlign
}
+ assert(endAlign >= maxFieldAlign);
+ assert(endAlign == getLowBit(blockSize));
+
// Slam everything else on now. This works because they have
// strictly decreasing alignment and we expect that size is always a
// multiple of alignment.
@@ -1130,15 +1134,17 @@
const VarDecl *variable = ci->getVariable();
DI->EmitLocation(Builder, variable->getLocation());
- const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
- if (capture.isConstant()) {
- DI->EmitDeclareOfAutoVariable(variable, LocalDeclMap[variable],
- Builder);
- continue;
- }
+ if (CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo) {
+ const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
+ if (capture.isConstant()) {
+ DI->EmitDeclareOfAutoVariable(variable, LocalDeclMap[variable],
+ Builder);
+ continue;
+ }
- DI->EmitDeclareOfBlockDeclRefVariable(variable, BlockPointer,
- Builder, blockInfo);
+ DI->EmitDeclareOfBlockDeclRefVariable(variable, BlockPointer,
+ Builder, blockInfo);
+ }
}
}
Modified: cfe/branches/tooling/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGBuiltin.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGBuiltin.cpp Tue May 8 03:47:31 2012
@@ -2411,8 +2411,11 @@
return llvm::Constant::getNullValue(ConvertType(E->getType()));
}
case X86::BI__builtin_ia32_movntps:
+ case X86::BI__builtin_ia32_movntps256:
case X86::BI__builtin_ia32_movntpd:
+ case X86::BI__builtin_ia32_movntpd256:
case X86::BI__builtin_ia32_movntdq:
+ case X86::BI__builtin_ia32_movntdq256:
case X86::BI__builtin_ia32_movnti: {
llvm::MDNode *Node = llvm::MDNode::get(getLLVMContext(),
Builder.getInt32(1));
Modified: cfe/branches/tooling/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGCXX.cpp Tue May 8 03:47:31 2012
@@ -53,7 +53,7 @@
// destructor separately.
for (CXXRecordDecl::field_iterator I = Class->field_begin(),
E = Class->field_end(); I != E; ++I)
- if ((*I)->getType().isDestructedType())
+ if (I->getType().isDestructedType())
return true;
// Try to find a unique base class with a non-trivial destructor.
Modified: cfe/branches/tooling/lib/CodeGen/CGCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGCXXABI.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGCXXABI.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGCXXABI.cpp Tue May 8 03:47:31 2012
@@ -145,6 +145,13 @@
}
CharUnits CGCXXABI::GetArrayCookieSize(const CXXNewExpr *expr) {
+ if (!requiresArrayCookie(expr))
+ return CharUnits::Zero();
+ return getArrayCookieSizeImpl(expr->getAllocatedType());
+}
+
+CharUnits CGCXXABI::getArrayCookieSizeImpl(QualType elementType) {
+ // BOGUS
return CharUnits::Zero();
}
@@ -158,16 +165,53 @@
return 0;
}
-void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
- const CXXDeleteExpr *expr, QualType ElementType,
- llvm::Value *&NumElements,
- llvm::Value *&AllocPtr, CharUnits &CookieSize) {
- ErrorUnsupportedABI(CGF, "array cookie reading");
-
- // This should be enough to avoid assertions.
- NumElements = 0;
- AllocPtr = llvm::Constant::getNullValue(CGF.Builder.getInt8PtrTy());
- CookieSize = CharUnits::Zero();
+bool CGCXXABI::requiresArrayCookie(const CXXDeleteExpr *expr,
+ QualType elementType) {
+ // If the class's usual deallocation function takes two arguments,
+ // it needs a cookie.
+ if (expr->doesUsualArrayDeleteWantSize())
+ return true;
+
+ return elementType.isDestructedType();
+}
+
+bool CGCXXABI::requiresArrayCookie(const CXXNewExpr *expr) {
+ // If the class's usual deallocation function takes two arguments,
+ // it needs a cookie.
+ if (expr->doesUsualArrayDeleteWantSize())
+ return true;
+
+ return expr->getAllocatedType().isDestructedType();
+}
+
+void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *ptr,
+ const CXXDeleteExpr *expr, QualType eltTy,
+ llvm::Value *&numElements,
+ llvm::Value *&allocPtr, CharUnits &cookieSize) {
+ // Derive a char* in the same address space as the pointer.
+ unsigned AS = cast<llvm::PointerType>(ptr->getType())->getAddressSpace();
+ llvm::Type *charPtrTy = CGF.Int8Ty->getPointerTo(AS);
+ ptr = CGF.Builder.CreateBitCast(ptr, charPtrTy);
+
+ // If we don't need an array cookie, bail out early.
+ if (!requiresArrayCookie(expr, eltTy)) {
+ allocPtr = ptr;
+ numElements = 0;
+ cookieSize = CharUnits::Zero();
+ return;
+ }
+
+ cookieSize = getArrayCookieSizeImpl(eltTy);
+ allocPtr = CGF.Builder.CreateConstInBoundsGEP1_64(ptr,
+ -cookieSize.getQuantity());
+ numElements = readArrayCookieImpl(CGF, allocPtr, cookieSize);
+}
+
+llvm::Value *CGCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
+ llvm::Value *ptr,
+ CharUnits cookieSize) {
+ ErrorUnsupportedABI(CGF, "reading a new[] cookie");
+ return llvm::ConstantInt::get(CGF.SizeTy, 0);
}
void CGCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
@@ -177,6 +221,13 @@
ErrorUnsupportedABI(CGF, "static local variable initialization");
}
+void CGCXXABI::registerGlobalDtor(CodeGenFunction &CGF,
+ llvm::Constant *dtor,
+ llvm::Constant *addr) {
+ // The default behavior is to use atexit.
+ CGF.registerGlobalDtorWithAtExit(dtor, addr);
+}
+
/// Returns the adjustment, in bytes, required for the given
/// member-pointer operation. Returns null if no adjustment is
/// required.
Modified: cfe/branches/tooling/lib/CodeGen/CGCXXABI.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGCXXABI.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGCXXABI.h (original)
+++ cfe/branches/tooling/lib/CodeGen/CGCXXABI.h Tue May 8 03:47:31 2012
@@ -71,6 +71,9 @@
ASTContext &getContext() const { return CGM.getContext(); }
+ virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
+ virtual bool requiresArrayCookie(const CXXNewExpr *E);
+
public:
virtual ~CGCXXABI();
@@ -209,7 +212,8 @@
/// \param NewPtr - a char* which is the presumed-non-null
/// return value of the allocation function
/// \param NumElements - the computed number of elements,
- /// potentially collapsed from the multidimensional array case
+ /// potentially collapsed from the multidimensional array case;
+ /// always a size_t
/// \param ElementType - the base element allocated type,
/// i.e. the allocated type after stripping all array types
virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
@@ -236,6 +240,25 @@
QualType ElementType, llvm::Value *&NumElements,
llvm::Value *&AllocPtr, CharUnits &CookieSize);
+protected:
+ /// Returns the extra size required in order to store the array
+ /// cookie for the given type. Assumes that an array cookie is
+ /// required.
+ virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
+
+ /// Reads the array cookie for an allocation which is known to have one.
+ /// This is called by the standard implementation of ReadArrayCookie.
+ ///
+ /// \param ptr - a pointer to the allocation made for an array, as a char*
+ /// \param cookieSize - the computed cookie size of an array
+ /// Other parameters are as above.
+ /// \return a size_t
+ virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
+ llvm::Value *ptr,
+ CharUnits cookieSize);
+
+public:
+
/*************************** Static local guards ****************************/
/// Emits the guarded initializer and destructor setup for the given
@@ -249,6 +272,13 @@
virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
llvm::GlobalVariable *DeclPtr, bool PerformInit);
+ /// Emit code to force the execution of a destructor during global
+ /// teardown. The default implementation of this uses atexit.
+ ///
+ /// \param dtor - a function taking a single pointer argument
+ /// \param addr - a pointer to pass to the destructor function.
+ virtual void registerGlobalDtor(CodeGenFunction &CGF, llvm::Constant *dtor,
+ llvm::Constant *addr);
};
/// Creates an instance of a C++ ABI class.
Modified: cfe/branches/tooling/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGCall.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGCall.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGCall.cpp Tue May 8 03:47:31 2012
@@ -431,7 +431,7 @@
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
assert(!FD->isBitField() &&
"Cannot expand structure with bit-field members.");
CharUnits FieldSize = getContext().getTypeSizeInChars(FD->getType());
@@ -445,10 +445,10 @@
} else {
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- const FieldDecl *FD = *i;
- assert(!FD->isBitField() &&
+ const FieldDecl &FD = *i;
+ assert(!FD.isBitField() &&
"Cannot expand structure with bit-field members.");
- GetExpandedTypes(FD->getType(), expandedTypes);
+ GetExpandedTypes(FD.getType(), expandedTypes);
}
}
} else if (const ComplexType *CT = type->getAs<ComplexType>()) {
@@ -483,7 +483,7 @@
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
assert(!FD->isBitField() &&
"Cannot expand structure with bit-field members.");
CharUnits FieldSize = getContext().getTypeSizeInChars(FD->getType());
@@ -500,7 +500,7 @@
} else {
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- FieldDecl *FD = *i;
+ FieldDecl *FD = &*i;
QualType FT = FD->getType();
// FIXME: What are the right qualifiers here?
@@ -1815,7 +1815,7 @@
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
assert(!FD->isBitField() &&
"Cannot expand structure with bit-field members.");
CharUnits FieldSize = getContext().getTypeSizeInChars(FD->getType());
@@ -1831,7 +1831,7 @@
} else {
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- FieldDecl *FD = *i;
+ FieldDecl *FD = &*i;
RValue FldRV = EmitRValueForField(LV, FD);
ExpandTypeToArgs(FD->getType(), FldRV, Args, IRFuncTy);
Modified: cfe/branches/tooling/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGClass.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGClass.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGClass.cpp Tue May 8 03:47:31 2012
@@ -808,7 +808,7 @@
// Check fields.
for (CXXRecordDecl::field_iterator I = BaseClassDecl->field_begin(),
E = BaseClassDecl->field_end(); I != E; ++I) {
- const FieldDecl *Field = *I;
+ const FieldDecl *Field = &*I;
if (!FieldHasTrivialDestructorBody(Context, Field))
return false;
@@ -869,7 +869,7 @@
const CXXRecordDecl *ClassDecl = Dtor->getParent();
for (CXXRecordDecl::field_iterator I = ClassDecl->field_begin(),
E = ClassDecl->field_end(); I != E; ++I) {
- const FieldDecl *Field = *I;
+ const FieldDecl *Field = &*I;
if (!FieldHasTrivialDestructorBody(Context, Field))
return false;
@@ -1066,7 +1066,7 @@
SmallVector<const FieldDecl *, 16> FieldDecls;
for (CXXRecordDecl::field_iterator I = ClassDecl->field_begin(),
E = ClassDecl->field_end(); I != E; ++I) {
- const FieldDecl *field = *I;
+ const FieldDecl *field = &*I;
QualType type = field->getType();
QualType::DestructionKind dtorKind = type.isDestructedType();
if (!dtorKind) continue;
@@ -1227,7 +1227,8 @@
CallExpr::const_arg_iterator ArgEnd) {
CGDebugInfo *DI = getDebugInfo();
- if (DI && CGM.getCodeGenOpts().LimitDebugInfo) {
+ if (DI &&
+ CGM.getCodeGenOpts().DebugInfo == CodeGenOptions::LimitedDebugInfo) {
// If debug info for this class has not been emitted then this is the
// right time to do so.
const CXXRecordDecl *Parent = D->getParent();
Modified: cfe/branches/tooling/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGDebugInfo.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGDebugInfo.cpp Tue May 8 03:47:31 2012
@@ -335,7 +335,7 @@
/// one if necessary.
llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) {
unsigned Encoding = 0;
- const char *BTName = NULL;
+ StringRef BTName;
switch (BT->getKind()) {
#define BUILTIN_TYPE(Id, SingletonId)
#define PLACEHOLDER_TYPE(Id, SingletonId) \
@@ -546,7 +546,7 @@
/// then emit record's fwd if debug info size reduction is enabled.
llvm::DIType CGDebugInfo::CreatePointeeType(QualType PointeeTy,
llvm::DIFile Unit) {
- if (!CGM.getCodeGenOpts().LimitDebugInfo)
+ if (CGM.getCodeGenOpts().DebugInfo != CodeGenOptions::LimitedDebugInfo)
return getOrCreateType(PointeeTy, Unit);
// Limit debug info for the pointee type.
@@ -797,7 +797,7 @@
for (RecordDecl::field_iterator I = record->field_begin(),
E = record->field_end();
I != E; ++I, ++fieldNo) {
- FieldDecl *field = *I;
+ FieldDecl *field = &*I;
if (IsMsStruct) {
// Zero-length bitfields following non-bitfield members are ignored
@@ -1176,6 +1176,7 @@
/// getOrCreateRecordType - Emit record type's standalone debug info.
llvm::DIType CGDebugInfo::getOrCreateRecordType(QualType RTy,
SourceLocation Loc) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
llvm::DIType T = getOrCreateType(RTy, getOrCreateFile(Loc));
return T;
}
@@ -1184,6 +1185,7 @@
/// debug info.
llvm::DIType CGDebugInfo::getOrCreateInterfaceType(QualType D,
SourceLocation Loc) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
llvm::DIType T = getOrCreateType(D, getOrCreateFile(Loc));
DBuilder.retainType(T);
return T;
@@ -1332,7 +1334,7 @@
for (ObjCContainerDecl::prop_iterator I = ID->prop_begin(),
E = ID->prop_end(); I != E; ++I) {
- const ObjCPropertyDecl *PD = *I;
+ const ObjCPropertyDecl *PD = &*I;
SourceLocation Loc = PD->getLocation();
llvm::DIFile PUnit = getOrCreateFile(Loc);
unsigned PLine = getLineNumber(Loc);
@@ -1823,7 +1825,7 @@
StringRef RDName = RD->getName();
llvm::DIDescriptor RDContext;
- if (CGM.getCodeGenOpts().LimitDebugInfo)
+ if (CGM.getCodeGenOpts().DebugInfo == CodeGenOptions::LimitedDebugInfo)
RDContext = createContextChain(cast<Decl>(RD->getDeclContext()));
else
RDContext = getContextDescriptor(cast<Decl>(RD->getDeclContext()));
@@ -2012,18 +2014,21 @@
LinkageName = CGM.getMangledName(GD);
Flags |= llvm::DIDescriptor::FlagPrototyped;
}
- if (LinkageName == Name)
+ if (LinkageName == Name ||
+ CGM.getCodeGenOpts().DebugInfo <= CodeGenOptions::DebugLineTablesOnly)
LinkageName = StringRef();
- if (const NamespaceDecl *NSDecl =
- dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
- FDContext = getOrCreateNameSpace(NSDecl);
- else if (const RecordDecl *RDecl =
- dyn_cast_or_null<RecordDecl>(FD->getDeclContext()))
- FDContext = getContextDescriptor(cast<Decl>(RDecl->getDeclContext()));
+ if (CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo) {
+ if (const NamespaceDecl *NSDecl =
+ dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
+ FDContext = getOrCreateNameSpace(NSDecl);
+ else if (const RecordDecl *RDecl =
+ dyn_cast_or_null<RecordDecl>(FD->getDeclContext()))
+ FDContext = getContextDescriptor(cast<Decl>(RDecl->getDeclContext()));
- // Collect template parameters.
- TParamsArray = CollectFunctionTemplateParams(FD, Unit);
+ // Collect template parameters.
+ TParamsArray = CollectFunctionTemplateParams(FD, Unit);
+ }
} else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
Name = getObjCMethodName(OMD);
Flags |= llvm::DIDescriptor::FlagPrototyped;
@@ -2039,14 +2044,27 @@
if (D->isImplicit())
Flags |= llvm::DIDescriptor::FlagArtificial;
- llvm::DISubprogram SPDecl = getFunctionDeclaration(D);
- llvm::DISubprogram SP =
- DBuilder.createFunction(FDContext, Name, LinkageName, Unit,
- LineNo, getOrCreateFunctionType(D, FnType, Unit),
- Fn->hasInternalLinkage(), true/*definition*/,
- getLineNumber(CurLoc),
- Flags, CGM.getLangOpts().Optimize, Fn,
- TParamsArray, SPDecl);
+ llvm::DIType DIFnType;
+ llvm::DISubprogram SPDecl;
+ if (CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo) {
+ DIFnType = getOrCreateFunctionType(D, FnType, Unit);
+ SPDecl = getFunctionDeclaration(D);
+ } else {
+ // Create fake but valid subroutine type. Otherwise
+ // llvm::DISubprogram::Verify() would return false, and
+ // subprogram DIE will miss DW_AT_decl_file and
+ // DW_AT_decl_line fields.
+ SmallVector<llvm::Value*, 16> Elts;
+ llvm::DIArray EltTypeArray = DBuilder.getOrCreateArray(Elts);
+ DIFnType = DBuilder.createSubroutineType(Unit, EltTypeArray);
+ }
+ llvm::DISubprogram SP;
+ SP = DBuilder.createFunction(FDContext, Name, LinkageName, Unit,
+ LineNo, DIFnType,
+ Fn->hasInternalLinkage(), true/*definition*/,
+ getLineNumber(CurLoc), Flags,
+ CGM.getLangOpts().Optimize,
+ Fn, TParamsArray, SPDecl);
// Push function on region stack.
llvm::MDNode *SPN = SP;
@@ -2204,6 +2222,7 @@
void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag,
llvm::Value *Storage,
unsigned ArgNo, CGBuilderTy &Builder) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
@@ -2293,7 +2312,7 @@
for (RecordDecl::field_iterator I = RD->field_begin(),
E = RD->field_end();
I != E; ++I) {
- FieldDecl *Field = *I;
+ FieldDecl *Field = &*I;
llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
StringRef FieldName = Field->getName();
@@ -2320,12 +2339,14 @@
void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD,
llvm::Value *Storage,
CGBuilderTy &Builder) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
EmitDeclare(VD, llvm::dwarf::DW_TAG_auto_variable, Storage, 0, Builder);
}
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
const VarDecl *VD, llvm::Value *Storage, CGBuilderTy &Builder,
const CGBlockInfo &blockInfo) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
if (Builder.GetInsertBlock() == 0)
@@ -2386,6 +2407,7 @@
void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI,
unsigned ArgNo,
CGBuilderTy &Builder) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
EmitDeclare(VD, llvm::dwarf::DW_TAG_arg_variable, AI, ArgNo, Builder);
}
@@ -2402,6 +2424,7 @@
void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
llvm::Value *addr,
CGBuilderTy &Builder) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
ASTContext &C = CGM.getContext();
const BlockDecl *blockDecl = block.getBlockDecl();
@@ -2546,6 +2569,7 @@
/// EmitGlobalVariable - Emit information about a global variable.
void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
const VarDecl *D) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
// Create global variable debug descriptor.
llvm::DIFile Unit = getOrCreateFile(D->getLocation());
unsigned LineNo = getLineNumber(D->getLocation());
@@ -2581,6 +2605,7 @@
/// EmitGlobalVariable - Emit information about an objective-c interface.
void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
ObjCInterfaceDecl *ID) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
// Create global variable debug descriptor.
llvm::DIFile Unit = getOrCreateFile(ID->getLocation());
unsigned LineNo = getLineNumber(ID->getLocation());
@@ -2608,6 +2633,7 @@
/// EmitGlobalVariable - Emit global variable's debug info.
void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
llvm::Constant *Init) {
+ assert(CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo);
// Create the descriptor for the variable.
llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
StringRef Name = VD->getName();
Modified: cfe/branches/tooling/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGDecl.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGDecl.cpp Tue May 8 03:47:31 2012
@@ -326,7 +326,8 @@
// Emit global variable debug descriptor for static vars.
CGDebugInfo *DI = getDebugInfo();
- if (DI) {
+ if (DI &&
+ CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo) {
DI->setLocation(D.getLocation());
DI->EmitGlobalVariable(var, &D);
}
@@ -897,11 +898,14 @@
// Emit debug info for local var declaration.
if (HaveInsertPoint())
if (CGDebugInfo *DI = getDebugInfo()) {
- DI->setLocation(D.getLocation());
- if (Target.useGlobalsForAutomaticVariables()) {
- DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D);
- } else
- DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder);
+ if (CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo) {
+ DI->setLocation(D.getLocation());
+ if (Target.useGlobalsForAutomaticVariables()) {
+ DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr),
+ &D);
+ } else
+ DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder);
+ }
}
if (D.hasAttr<AnnotateAttr>())
@@ -1477,8 +1481,11 @@
LocalDeclMap[&D] = Arg;
if (CGDebugInfo *DI = getDebugInfo()) {
- DI->setLocation(D.getLocation());
- DI->EmitDeclareOfBlockLiteralArgVariable(*BlockInfo, Arg, Builder);
+ if (CGM.getCodeGenOpts().DebugInfo >=
+ CodeGenOptions::LimitedDebugInfo) {
+ DI->setLocation(D.getLocation());
+ DI->EmitDeclareOfBlockLiteralArgVariable(*BlockInfo, Arg, Builder);
+ }
}
return;
@@ -1556,8 +1563,11 @@
DMEntry = DeclPtr;
// Emit debug info for param declaration.
- if (CGDebugInfo *DI = getDebugInfo())
- DI->EmitDeclareOfArgVariable(&D, DeclPtr, ArgNo, Builder);
+ if (CGDebugInfo *DI = getDebugInfo()) {
+ if (CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo) {
+ DI->EmitDeclareOfArgVariable(&D, DeclPtr, ArgNo, Builder);
+ }
+ }
if (D.hasAttr<AnnotateAttr>())
EmitVarAnnotations(&D, DeclPtr);
Modified: cfe/branches/tooling/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGDeclCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGDeclCXX.cpp Tue May 8 03:47:31 2012
@@ -98,7 +98,7 @@
argument = llvm::Constant::getNullValue(CGF.Int8PtrTy);
}
- CGF.EmitCXXGlobalDtorRegistration(function, argument);
+ CGM.getCXXABI().registerGlobalDtor(CGF, function, argument);
}
/// Emit code to cause the variable at the given address to be considered as
@@ -145,39 +145,6 @@
EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
}
-/// Register a global destructor using __cxa_atexit.
-static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
- llvm::Constant *dtor,
- llvm::Constant *addr) {
- // We're assuming that the destructor function is something we can
- // reasonably call with the default CC. Go ahead and cast it to the
- // right prototype.
- llvm::Type *dtorTy =
- llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, false)->getPointerTo();
-
- // extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
- llvm::Type *paramTys[] = { dtorTy, CGF.Int8PtrTy, CGF.Int8PtrTy };
- llvm::FunctionType *atexitTy =
- llvm::FunctionType::get(CGF.IntTy, paramTys, false);
-
- // Fetch the actual function.
- llvm::Constant *atexit =
- CGF.CGM.CreateRuntimeFunction(atexitTy, "__cxa_atexit");
- if (llvm::Function *fn = dyn_cast<llvm::Function>(atexit))
- fn->setDoesNotThrow();
-
- // Create a variable that binds the atexit to this shared object.
- llvm::Constant *handle =
- CGF.CGM.CreateRuntimeVariable(CGF.Int8Ty, "__dso_handle");
-
- llvm::Value *args[] = {
- llvm::ConstantExpr::getBitCast(dtor, dtorTy),
- llvm::ConstantExpr::getBitCast(addr, CGF.Int8PtrTy),
- handle
- };
- CGF.Builder.CreateCall(atexit, args);
-}
-
static llvm::Function *
CreateGlobalInitOrDestructFunction(CodeGenModule &CGM,
llvm::FunctionType *ty,
@@ -212,43 +179,22 @@
return fn;
}
-/// Register a global destructor using atexit.
-static void emitGlobalDtorWithAtExit(CodeGenFunction &CGF,
- llvm::Constant *dtor,
- llvm::Constant *addr) {
+/// Register a global destructor using the C atexit runtime function.
+void CodeGenFunction::registerGlobalDtorWithAtExit(llvm::Constant *dtor,
+ llvm::Constant *addr) {
// Create a function which calls the destructor.
- llvm::Constant *dtorStub = createAtExitStub(CGF.CGM, dtor, addr);
+ llvm::Constant *dtorStub = createAtExitStub(CGM, dtor, addr);
// extern "C" int atexit(void (*f)(void));
llvm::FunctionType *atexitTy =
- llvm::FunctionType::get(CGF.IntTy, dtorStub->getType(), false);
+ llvm::FunctionType::get(IntTy, dtorStub->getType(), false);
llvm::Constant *atexit =
- CGF.CGM.CreateRuntimeFunction(atexitTy, "atexit");
+ CGM.CreateRuntimeFunction(atexitTy, "atexit");
if (llvm::Function *atexitFn = dyn_cast<llvm::Function>(atexit))
atexitFn->setDoesNotThrow();
- CGF.Builder.CreateCall(atexit, dtorStub);
-}
-
-void CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *dtor,
- llvm::Constant *addr) {
- // Use __cxa_atexit if available.
- if (CGM.getCodeGenOpts().CXAAtExit) {
- emitGlobalDtorWithCXAAtExit(*this, dtor, addr);
- return;
- }
-
- // In Apple kexts, we want to add a global destructor entry.
- // FIXME: shouldn't this be guarded by some variable?
- if (CGM.getContext().getLangOpts().AppleKext) {
- // Generate a global destructor entry.
- CGM.AddCXXDtorEntry(dtor, addr);
- return;
- }
-
- // Otherwise, we just use atexit.
- emitGlobalDtorWithAtExit(*this, dtor, addr);
+ Builder.CreateCall(atexit, dtorStub)->setDoesNotThrow();
}
void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D,
Modified: cfe/branches/tooling/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGExpr.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGExpr.cpp Tue May 8 03:47:31 2012
@@ -462,7 +462,7 @@
if (ReferenceTemporaryDtor) {
llvm::Constant *DtorFn =
CGM.GetAddrOfCXXDestructor(ReferenceTemporaryDtor, Dtor_Complete);
- EmitCXXGlobalDtorRegistration(DtorFn,
+ CGM.getCXXABI().registerGlobalDtor(*this, DtorFn,
cast<llvm::Constant>(ReferenceTemporary));
} else {
assert(!ObjCARCReferenceLifetimeType.isNull());
@@ -525,15 +525,9 @@
llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::objectsize, IntPtrTy);
- // In time, people may want to control this and use a 1 here.
llvm::Value *Arg = Builder.getFalse();
llvm::Value *C = Builder.CreateCall2(F, Address, Arg);
llvm::BasicBlock *Cont = createBasicBlock();
- llvm::BasicBlock *Check = createBasicBlock();
- llvm::Value *NegativeOne = llvm::ConstantInt::get(IntPtrTy, -1ULL);
- Builder.CreateCondBr(Builder.CreateICmpEQ(C, NegativeOne), Cont, Check);
-
- EmitBlock(Check);
Builder.CreateCondBr(Builder.CreateICmpUGE(C,
llvm::ConstantInt::get(IntPtrTy, Size)),
Cont, getTrapBB());
@@ -880,7 +874,6 @@
CGM.getCodeGenOpts().StrictEnums &&
!ET->getDecl()->isFixed());
bool IsBool = hasBooleanRepresentation(Ty);
- llvm::Type *LTy;
if (!IsBool && !IsRegularCPlusPlusEnum)
return NULL;
@@ -889,10 +882,9 @@
if (IsBool) {
Min = llvm::APInt(8, 0);
End = llvm::APInt(8, 2);
- LTy = Int8Ty;
} else {
const EnumDecl *ED = ET->getDecl();
- LTy = ConvertTypeForMem(ED->getIntegerType());
+ llvm::Type *LTy = ConvertTypeForMem(ED->getIntegerType());
unsigned Bitwidth = LTy->getScalarSizeInBits();
unsigned NumNegativeBits = ED->getNumNegativeBits();
unsigned NumPositiveBits = ED->getNumPositiveBits();
@@ -1794,25 +1786,6 @@
// Extend or truncate the index type to 32 or 64-bits.
if (Idx->getType() != IntPtrTy)
Idx = Builder.CreateIntCast(Idx, IntPtrTy, IdxSigned, "idxprom");
-
- // FIXME: As llvm implements the object size checking, this can come out.
- if (CatchUndefined) {
- if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E->getBase())){
- if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) {
- if (ICE->getCastKind() == CK_ArrayToPointerDecay) {
- if (const ConstantArrayType *CAT
- = getContext().getAsConstantArrayType(DRE->getType())) {
- llvm::APInt Size = CAT->getSize();
- llvm::BasicBlock *Cont = createBasicBlock("cont");
- Builder.CreateCondBr(Builder.CreateICmpULE(Idx,
- llvm::ConstantInt::get(Idx->getType(), Size)),
- Cont, getTrapBB());
- EmitBlock(Cont);
- }
- }
- }
- }
- }
// We know that the pointer points to a type of the correct size, unless the
// size is a VLA or Objective-C interface.
Modified: cfe/branches/tooling/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGExprAgg.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGExprAgg.cpp Tue May 8 03:47:31 2012
@@ -352,7 +352,7 @@
return;
}
LValue DestLV = CGF.MakeNaturalAlignAddrLValue(destPtr, initList->getType());
- LValue start = CGF.EmitLValueForFieldInitialization(DestLV, *field);
+ LValue start = CGF.EmitLValueForFieldInitialization(DestLV, &*field);
llvm::Value *arrayStart = Builder.CreateStructGEP(alloc, 0, "arraystart");
CGF.EmitStoreThroughLValue(RValue::get(arrayStart), start);
++field;
@@ -361,7 +361,7 @@
CGF.ErrorUnsupported(initList, "weird std::initializer_list");
return;
}
- LValue endOrLength = CGF.EmitLValueForFieldInitialization(DestLV, *field);
+ LValue endOrLength = CGF.EmitLValueForFieldInitialization(DestLV, &*field);
if (ctx.hasSameType(field->getType(), elementPtr)) {
// End pointer.
llvm::Value *arrayEnd = Builder.CreateStructGEP(alloc,numInits, "arrayend");
@@ -1005,7 +1005,7 @@
break;
- LValue LV = CGF.EmitLValueForFieldInitialization(DestLV, *field);
+ LValue LV = CGF.EmitLValueForFieldInitialization(DestLV, &*field);
// We never generate write-barries for initialized fields.
LV.setNonGC(true);
Modified: cfe/branches/tooling/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGExprCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGExprCXX.cpp Tue May 8 03:47:31 2012
@@ -179,7 +179,7 @@
const CXXMethodDecl *MD = cast<CXXMethodDecl>(ME->getMemberDecl());
CGDebugInfo *DI = getDebugInfo();
- if (DI && CGM.getCodeGenOpts().LimitDebugInfo
+ if (DI && CGM.getCodeGenOpts().DebugInfo == CodeGenOptions::LimitedDebugInfo
&& !isa<CallExpr>(ME->getBase())) {
QualType PQTy = ME->getBase()->IgnoreParenImpCasts()->getType();
if (const PointerType * PTy = dyn_cast<PointerType>(PQTy)) {
@@ -1824,10 +1824,10 @@
i != e; ++i, ++CurField) {
// Emit initialization
- LValue LV = EmitLValueForFieldInitialization(SlotLV, *CurField);
+ LValue LV = EmitLValueForFieldInitialization(SlotLV, &*CurField);
ArrayRef<VarDecl *> ArrayIndexes;
if (CurField->getType()->isArrayType())
ArrayIndexes = E->getCaptureInitIndexVars(i);
- EmitInitializerForField(*CurField, LV, *i, ArrayIndexes);
+ EmitInitializerForField(&*CurField, LV, *i, ArrayIndexes);
}
}
Modified: cfe/branches/tooling/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGExprConstant.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGExprConstant.cpp Tue May 8 03:47:31 2012
@@ -386,20 +386,20 @@
if (IsMsStruct) {
// Zero-length bitfields following non-bitfield members are
// ignored:
- if (CGM.getContext().ZeroBitfieldFollowsNonBitfield((*Field), LastFD)) {
+ if (CGM.getContext().ZeroBitfieldFollowsNonBitfield(&*Field, LastFD)) {
--FieldNo;
continue;
}
- LastFD = (*Field);
+ LastFD = &*Field;
}
// If this is a union, skip all the fields that aren't being initialized.
- if (RD->isUnion() && ILE->getInitializedFieldInUnion() != *Field)
+ if (RD->isUnion() && ILE->getInitializedFieldInUnion() != &*Field)
continue;
// Don't emit anonymous bitfields, they just affect layout.
if (Field->isUnnamedBitfield()) {
- LastFD = (*Field);
+ LastFD = &*Field;
continue;
}
@@ -417,10 +417,10 @@
if (!Field->isBitField()) {
// Handle non-bitfield members.
- AppendField(*Field, Layout.getFieldOffset(FieldNo), EltInit);
+ AppendField(&*Field, Layout.getFieldOffset(FieldNo), EltInit);
} else {
// Otherwise we have a bitfield.
- AppendBitField(*Field, Layout.getFieldOffset(FieldNo),
+ AppendBitField(&*Field, Layout.getFieldOffset(FieldNo),
cast<llvm::ConstantInt>(EltInit));
}
}
@@ -486,20 +486,20 @@
if (IsMsStruct) {
// Zero-length bitfields following non-bitfield members are
// ignored:
- if (CGM.getContext().ZeroBitfieldFollowsNonBitfield((*Field), LastFD)) {
+ if (CGM.getContext().ZeroBitfieldFollowsNonBitfield(&*Field, LastFD)) {
--FieldNo;
continue;
}
- LastFD = (*Field);
+ LastFD = &*Field;
}
// If this is a union, skip all the fields that aren't being initialized.
- if (RD->isUnion() && Val.getUnionField() != *Field)
+ if (RD->isUnion() && Val.getUnionField() != &*Field)
continue;
// Don't emit anonymous bitfields, they just affect layout.
if (Field->isUnnamedBitfield()) {
- LastFD = (*Field);
+ LastFD = &*Field;
continue;
}
@@ -512,10 +512,10 @@
if (!Field->isBitField()) {
// Handle non-bitfield members.
- AppendField(*Field, Layout.getFieldOffset(FieldNo) + OffsetBits, EltInit);
+ AppendField(&*Field, Layout.getFieldOffset(FieldNo) + OffsetBits, EltInit);
} else {
// Otherwise we have a bitfield.
- AppendBitField(*Field, Layout.getFieldOffset(FieldNo) + OffsetBits,
+ AppendBitField(&*Field, Layout.getFieldOffset(FieldNo) + OffsetBits,
cast<llvm::ConstantInt>(EltInit));
}
}
@@ -1374,7 +1374,7 @@
// Fill in all the fields.
for (RecordDecl::field_iterator I = record->field_begin(),
E = record->field_end(); I != E; ++I) {
- const FieldDecl *field = *I;
+ const FieldDecl *field = &*I;
// Fill in non-bitfields. (Bitfields always use a zero pattern, which we
// will fill in later.)
Modified: cfe/branches/tooling/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGExprScalar.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGExprScalar.cpp Tue May 8 03:47:31 2012
@@ -798,14 +798,15 @@
return Builder.getInt(Value);
}
- // Emit debug info for aggregate now, if it was delayed to reduce
+ // Emit debug info for aggregate now, if it was delayed to reduce
// debug info size.
CGDebugInfo *DI = CGF.getDebugInfo();
- if (DI && CGF.CGM.getCodeGenOpts().LimitDebugInfo) {
+ if (DI &&
+ CGF.CGM.getCodeGenOpts().DebugInfo == CodeGenOptions::LimitedDebugInfo) {
QualType PQTy = E->getBase()->IgnoreParenImpCasts()->getType();
if (const PointerType * PTy = dyn_cast<PointerType>(PQTy))
if (FieldDecl *M = dyn_cast<FieldDecl>(E->getMemberDecl()))
- DI->getOrCreateRecordType(PTy->getPointeeType(),
+ DI->getOrCreateRecordType(PTy->getPointeeType(),
M->getParent()->getLocation());
}
return EmitLoadOfLValue(E);
@@ -1520,8 +1521,8 @@
// FIXME: It would be nice if we didn't have to loop here!
for (RecordDecl::field_iterator Field = RD->field_begin(),
FieldEnd = RD->field_end();
- Field != FieldEnd; (void)++Field, ++i) {
- if (*Field == MemberDecl)
+ Field != FieldEnd; ++Field, ++i) {
+ if (&*Field == MemberDecl)
break;
}
assert(i < RL.getFieldCount() && "offsetof field in wrong type");
Modified: cfe/branches/tooling/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGObjC.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGObjC.cpp Tue May 8 03:47:31 2012
@@ -859,7 +859,7 @@
// always objects so we don't need to worry about complex or
// aggregates.
RV = RValue::get(Builder.CreateBitCast(RV.getScalarVal(),
- getTypes().ConvertType(propType)));
+ getTypes().ConvertType(getterMethod->getResultType())));
EmitReturnOfRValue(RV, propType);
Modified: cfe/branches/tooling/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGObjCGNU.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGObjCGNU.cpp Tue May 8 03:47:31 2012
@@ -1627,7 +1627,7 @@
iter = PD->prop_begin(), endIter = PD->prop_end();
iter != endIter ; iter++) {
std::vector<llvm::Constant*> Fields;
- ObjCPropertyDecl *property = (*iter);
+ ObjCPropertyDecl *property = &*iter;
Fields.push_back(MakeConstantString(property->getNameAsString()));
Fields.push_back(llvm::ConstantInt::get(Int8Ty,
@@ -1877,8 +1877,8 @@
iter = OID->propimpl_begin(), endIter = OID->propimpl_end();
iter != endIter ; iter++) {
std::vector<llvm::Constant*> Fields;
- ObjCPropertyDecl *property = (*iter)->getPropertyDecl();
- ObjCPropertyImplDecl *propertyImpl = *iter;
+ ObjCPropertyDecl *property = iter->getPropertyDecl();
+ ObjCPropertyImplDecl *propertyImpl = &*iter;
bool isSynthesized = (propertyImpl->getPropertyImplementation() ==
ObjCPropertyImplDecl::Synthesize);
Modified: cfe/branches/tooling/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGObjCMac.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGObjCMac.cpp Tue May 8 03:47:31 2012
@@ -2121,7 +2121,7 @@
PushProtocolProperties(PropertySet, Properties, Container, (*P), ObjCTypes);
for (ObjCContainerDecl::prop_iterator I = PROTO->prop_begin(),
E = PROTO->prop_end(); I != E; ++I) {
- const ObjCPropertyDecl *PD = *I;
+ const ObjCPropertyDecl *PD = &*I;
if (!PropertySet.insert(PD->getIdentifier()))
continue;
llvm::Constant *Prop[] = {
@@ -2152,7 +2152,7 @@
llvm::SmallPtrSet<const IdentifierInfo*, 16> PropertySet;
for (ObjCContainerDecl::prop_iterator I = OCD->prop_begin(),
E = OCD->prop_end(); I != E; ++I) {
- const ObjCPropertyDecl *PD = *I;
+ const ObjCPropertyDecl *PD = &*I;
PropertySet.insert(PD->getIdentifier());
llvm::Constant *Prop[] = {
GetPropertyName(PD->getIdentifier()),
@@ -2403,7 +2403,7 @@
for (ObjCImplementationDecl::propimpl_iterator
i = ID->propimpl_begin(), e = ID->propimpl_end(); i != e; ++i) {
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) {
ObjCPropertyDecl *PD = PID->getPropertyDecl();
@@ -3818,7 +3818,10 @@
bool &HasUnion) {
const RecordDecl *RD = RT->getDecl();
// FIXME - Use iterator.
- SmallVector<const FieldDecl*, 16> Fields(RD->field_begin(), RD->field_end());
+ SmallVector<const FieldDecl*, 16> Fields;
+ for (RecordDecl::field_iterator i = RD->field_begin(),
+ e = RD->field_end(); i != e; ++i)
+ Fields.push_back(&*i);
llvm::Type *Ty = CGM.getTypes().ConvertType(QualType(RT, 0));
const llvm::StructLayout *RecLayout =
CGM.getTargetData().getStructLayout(cast<llvm::StructType>(Ty));
@@ -5001,7 +5004,7 @@
}
for (ObjCImplementationDecl::propimpl_iterator
i = ID->propimpl_begin(), e = ID->propimpl_end(); i != e; ++i) {
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize){
ObjCPropertyDecl *PD = PID->getPropertyDecl();
Modified: cfe/branches/tooling/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGRecordLayoutBuilder.cpp Tue May 8 03:47:31 2012
@@ -538,7 +538,7 @@
fieldEnd = D->field_end(); field != fieldEnd; ++field, ++fieldNo) {
assert(layout.getFieldOffset(fieldNo) == 0 &&
"Union field offset did not start at the beginning of record!");
- llvm::Type *fieldType = LayoutUnionField(*field, layout);
+ llvm::Type *fieldType = LayoutUnionField(&*field, layout);
if (!fieldType)
continue;
@@ -714,14 +714,18 @@
}
// Otherwise, add a vtable / vf-table if the layout says to do so.
- } else if (Types.getContext().getTargetInfo().getCXXABI() == CXXABI_Microsoft
- ? Layout.getVFPtrOffset() != CharUnits::fromQuantity(-1)
- : RD->isDynamicClass()) {
+ } else if (Layout.hasOwnVFPtr()) {
llvm::Type *FunctionType =
llvm::FunctionType::get(llvm::Type::getInt32Ty(Types.getLLVMContext()),
/*isVarArg=*/true);
llvm::Type *VTableTy = FunctionType->getPointerTo();
-
+
+ if (getTypeAlignment(VTableTy) > Alignment) {
+ // FIXME: Should we allow this to happen in Sema?
+ assert(!Packed && "Alignment is wrong even with packed struct!");
+ return false;
+ }
+
assert(NextFieldOffset.isZero() &&
"VTable pointer must come first!");
AppendField(CharUnits::Zero(), VTableTy->getPointerTo());
@@ -814,7 +818,7 @@
if (IsMsStruct) {
// Zero-length bitfields following non-bitfield members are
// ignored:
- const FieldDecl *FD = (*Field);
+ const FieldDecl *FD = &*Field;
if (Types.getContext().ZeroBitfieldFollowsNonBitfield(FD, LastFD)) {
--FieldNo;
continue;
@@ -822,7 +826,7 @@
LastFD = FD;
}
- if (!LayoutField(*Field, Layout.getFieldOffset(FieldNo))) {
+ if (!LayoutField(&*Field, Layout.getFieldOffset(FieldNo))) {
assert(!Packed &&
"Could not layout fields even with a packed LLVM struct!");
return false;
@@ -1057,7 +1061,7 @@
const FieldDecl *LastFD = 0;
bool IsMsStruct = D->hasAttr<MsStructAttr>();
for (unsigned i = 0, e = AST_RL.getFieldCount(); i != e; ++i, ++it) {
- const FieldDecl *FD = *it;
+ const FieldDecl *FD = &*it;
// For non-bit-fields, just check that the LLVM struct offset matches the
// AST offset.
@@ -1118,7 +1122,7 @@
const RecordDecl *RD = it->first->getParent();
unsigned Index = 0;
for (RecordDecl::field_iterator
- it2 = RD->field_begin(); *it2 != it->first; ++it2)
+ it2 = RD->field_begin(); &*it2 != it->first; ++it2)
++Index;
BFIs.push_back(std::make_pair(Index, &it->second));
}
Modified: cfe/branches/tooling/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CGStmt.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CGStmt.cpp Tue May 8 03:47:31 2012
@@ -1441,7 +1441,7 @@
std::vector<QualType> ResultRegQualTys;
std::vector<llvm::Type *> ResultRegTypes;
std::vector<llvm::Type *> ResultTruncRegTypes;
- std::vector<llvm::Type*> ArgTypes;
+ std::vector<llvm::Type *> ArgTypes;
std::vector<llvm::Value*> Args;
// Keep track of inout constraints.
Modified: cfe/branches/tooling/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CodeGenFunction.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CodeGenFunction.cpp Tue May 8 03:47:31 2012
@@ -1087,7 +1087,8 @@
llvm::Constant *Init) {
assert (Init && "Invalid DeclRefExpr initializer!");
if (CGDebugInfo *Dbg = getDebugInfo())
- Dbg->EmitGlobalVariable(E->getDecl(), Init);
+ if (CGM.getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo)
+ Dbg->EmitGlobalVariable(E->getDecl(), Init);
}
CodeGenFunction::PeepholeProtection
Modified: cfe/branches/tooling/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CodeGenFunction.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/branches/tooling/lib/CodeGen/CodeGenFunction.h Tue May 8 03:47:31 2012
@@ -2411,10 +2411,9 @@
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr,
bool PerformInit);
- /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr
- /// with the C++ runtime so that its destructor will be called at exit.
- void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
- llvm::Constant *DeclPtr);
+ /// Call atexit() with a function that passes the given argument to
+ /// the given function.
+ void registerGlobalDtorWithAtExit(llvm::Constant *fn, llvm::Constant *addr);
/// Emit code in this function to perform a guarded variable
/// initialization. Guarded initializations are used when it's not
Modified: cfe/branches/tooling/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CodeGenModule.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/CodeGenModule.cpp Tue May 8 03:47:31 2012
@@ -110,7 +110,8 @@
// If debug info or coverage generation is enabled, create the CGDebugInfo
// object.
- if (CodeGenOpts.DebugInfo || CodeGenOpts.EmitGcovArcs ||
+ if (CodeGenOpts.DebugInfo != CodeGenOptions::NoDebugInfo ||
+ CodeGenOpts.EmitGcovArcs ||
CodeGenOpts.EmitGcovNotes)
DebugInfo = new CGDebugInfo(*this);
@@ -1605,7 +1606,8 @@
// Emit global variable debug information.
if (CGDebugInfo *DI = getModuleDebugInfo())
- DI->EmitGlobalVariable(GV, D);
+ if (getCodeGenOpts().DebugInfo >= CodeGenOptions::LimitedDebugInfo)
+ DI->EmitGlobalVariable(GV, D);
}
llvm::GlobalValue::LinkageTypes
@@ -2343,7 +2345,7 @@
ObjCImplementationDecl *D) {
for (ObjCImplementationDecl::propimpl_iterator
i = D->propimpl_begin(), e = D->propimpl_end(); i != e; ++i) {
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
// Dynamic is just for type-checking.
if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) {
Modified: cfe/branches/tooling/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/CodeGenModule.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/branches/tooling/lib/CodeGen/CodeGenModule.h Tue May 8 03:47:31 2012
@@ -138,6 +138,7 @@
union {
unsigned char PointerAlignInBytes;
unsigned char PointerSizeInBytes;
+ unsigned char SizeSizeInBytes; // sizeof(size_t)
};
};
Modified: cfe/branches/tooling/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/ItaniumCXXABI.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/ItaniumCXXABI.cpp Tue May 8 03:47:31 2012
@@ -48,10 +48,6 @@
return PtrDiffTy;
}
- bool NeedsArrayCookie(const CXXNewExpr *expr);
- bool NeedsArrayCookie(const CXXDeleteExpr *expr,
- QualType elementType);
-
public:
ItaniumCXXABI(CodeGen::CodeGenModule &CGM, bool IsARM = false) :
CGCXXABI(CGM), PtrDiffTy(0), IsARM(IsARM) { }
@@ -111,19 +107,20 @@
void EmitInstanceFunctionProlog(CodeGenFunction &CGF);
- CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
+ CharUnits getArrayCookieSizeImpl(QualType elementType);
llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
llvm::Value *NewPtr,
llvm::Value *NumElements,
const CXXNewExpr *expr,
QualType ElementType);
- void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
- const CXXDeleteExpr *expr,
- QualType ElementType, llvm::Value *&NumElements,
- llvm::Value *&AllocPtr, CharUnits &CookieSize);
+ llvm::Value *readArrayCookieImpl(CodeGenFunction &CGF,
+ llvm::Value *allocPtr,
+ CharUnits cookieSize);
void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
llvm::GlobalVariable *DeclPtr, bool PerformInit);
+ void registerGlobalDtor(CodeGenFunction &CGF, llvm::Constant *dtor,
+ llvm::Constant *addr);
};
class ARMCXXABI : public ItaniumCXXABI {
@@ -148,16 +145,14 @@
void EmitReturnFromThunk(CodeGenFunction &CGF, RValue RV, QualType ResTy);
- CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
+ CharUnits getArrayCookieSizeImpl(QualType elementType);
llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
llvm::Value *NewPtr,
llvm::Value *NumElements,
const CXXNewExpr *expr,
QualType ElementType);
- void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
- const CXXDeleteExpr *expr,
- QualType ElementType, llvm::Value *&NumElements,
- llvm::Value *&AllocPtr, CharUnits &CookieSize);
+ llvm::Value *readArrayCookieImpl(CodeGenFunction &CGF, llvm::Value *allocPtr,
+ CharUnits cookieSize);
private:
/// \brief Returns true if the given instance method is one of the
@@ -796,54 +791,11 @@
/************************** Array allocation cookies **************************/
-bool ItaniumCXXABI::NeedsArrayCookie(const CXXNewExpr *expr) {
- // If the class's usual deallocation function takes two arguments,
- // it needs a cookie.
- if (expr->doesUsualArrayDeleteWantSize())
- return true;
-
- // Automatic Reference Counting:
- // We need an array cookie for pointers with strong or weak lifetime.
- QualType AllocatedType = expr->getAllocatedType();
- if (getContext().getLangOpts().ObjCAutoRefCount &&
- AllocatedType->isObjCLifetimeType()) {
- switch (AllocatedType.getObjCLifetime()) {
- case Qualifiers::OCL_None:
- case Qualifiers::OCL_ExplicitNone:
- case Qualifiers::OCL_Autoreleasing:
- return false;
-
- case Qualifiers::OCL_Strong:
- case Qualifiers::OCL_Weak:
- return true;
- }
- }
-
- // Otherwise, if the class has a non-trivial destructor, it always
- // needs a cookie.
- const CXXRecordDecl *record =
- AllocatedType->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
- return (record && !record->hasTrivialDestructor());
-}
-
-bool ItaniumCXXABI::NeedsArrayCookie(const CXXDeleteExpr *expr,
- QualType elementType) {
- // If the class's usual deallocation function takes two arguments,
- // it needs a cookie.
- if (expr->doesUsualArrayDeleteWantSize())
- return true;
-
- return elementType.isDestructedType();
-}
-
-CharUnits ItaniumCXXABI::GetArrayCookieSize(const CXXNewExpr *expr) {
- if (!NeedsArrayCookie(expr))
- return CharUnits::Zero();
-
- // Padding is the maximum of sizeof(size_t) and alignof(elementType)
- ASTContext &Ctx = getContext();
- return std::max(Ctx.getTypeSizeInChars(Ctx.getSizeType()),
- Ctx.getTypeAlignInChars(expr->getAllocatedType()));
+CharUnits ItaniumCXXABI::getArrayCookieSizeImpl(QualType elementType) {
+ // The array cookie is a size_t; pad that up to the element alignment.
+ // The cookie is actually right-justified in that space.
+ return std::max(CharUnits::fromQuantity(CGM.SizeSizeInBytes),
+ CGM.getContext().getTypeAlignInChars(elementType));
}
llvm::Value *ItaniumCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
@@ -851,7 +803,7 @@
llvm::Value *NumElements,
const CXXNewExpr *expr,
QualType ElementType) {
- assert(NeedsArrayCookie(expr));
+ assert(requiresArrayCookie(expr));
unsigned AS = cast<llvm::PointerType>(NewPtr->getType())->getAddressSpace();
@@ -862,6 +814,7 @@
// The size of the cookie.
CharUnits CookieSize =
std::max(SizeSize, Ctx.getTypeAlignInChars(ElementType));
+ assert(CookieSize == getArrayCookieSizeImpl(ElementType));
// Compute an offset to the cookie.
llvm::Value *CookiePtr = NewPtr;
@@ -882,53 +835,25 @@
CookieSize.getQuantity());
}
-void ItaniumCXXABI::ReadArrayCookie(CodeGenFunction &CGF,
- llvm::Value *Ptr,
- const CXXDeleteExpr *expr,
- QualType ElementType,
- llvm::Value *&NumElements,
- llvm::Value *&AllocPtr,
- CharUnits &CookieSize) {
- // Derive a char* in the same address space as the pointer.
- unsigned AS = cast<llvm::PointerType>(Ptr->getType())->getAddressSpace();
- llvm::Type *CharPtrTy = CGF.Builder.getInt8Ty()->getPointerTo(AS);
-
- // If we don't need an array cookie, bail out early.
- if (!NeedsArrayCookie(expr, ElementType)) {
- AllocPtr = CGF.Builder.CreateBitCast(Ptr, CharPtrTy);
- NumElements = 0;
- CookieSize = CharUnits::Zero();
- return;
- }
-
- QualType SizeTy = getContext().getSizeType();
- CharUnits SizeSize = getContext().getTypeSizeInChars(SizeTy);
- llvm::Type *SizeLTy = CGF.ConvertType(SizeTy);
-
- CookieSize
- = std::max(SizeSize, getContext().getTypeAlignInChars(ElementType));
-
- CharUnits NumElementsOffset = CookieSize - SizeSize;
-
- // Compute the allocated pointer.
- AllocPtr = CGF.Builder.CreateBitCast(Ptr, CharPtrTy);
- AllocPtr = CGF.Builder.CreateConstInBoundsGEP1_64(AllocPtr,
- -CookieSize.getQuantity());
-
- llvm::Value *NumElementsPtr = AllocPtr;
- if (!NumElementsOffset.isZero())
- NumElementsPtr =
- CGF.Builder.CreateConstInBoundsGEP1_64(NumElementsPtr,
- NumElementsOffset.getQuantity());
- NumElementsPtr =
- CGF.Builder.CreateBitCast(NumElementsPtr, SizeLTy->getPointerTo(AS));
- NumElements = CGF.Builder.CreateLoad(NumElementsPtr);
-}
-
-CharUnits ARMCXXABI::GetArrayCookieSize(const CXXNewExpr *expr) {
- if (!NeedsArrayCookie(expr))
- return CharUnits::Zero();
+llvm::Value *ItaniumCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
+ llvm::Value *allocPtr,
+ CharUnits cookieSize) {
+ // The element size is right-justified in the cookie.
+ llvm::Value *numElementsPtr = allocPtr;
+ CharUnits numElementsOffset =
+ cookieSize - CharUnits::fromQuantity(CGF.SizeSizeInBytes);
+ if (!numElementsOffset.isZero())
+ numElementsPtr =
+ CGF.Builder.CreateConstInBoundsGEP1_64(numElementsPtr,
+ numElementsOffset.getQuantity());
+
+ unsigned AS = cast<llvm::PointerType>(allocPtr->getType())->getAddressSpace();
+ numElementsPtr =
+ CGF.Builder.CreateBitCast(numElementsPtr, CGF.SizeTy->getPointerTo(AS));
+ return CGF.Builder.CreateLoad(numElementsPtr);
+}
+CharUnits ARMCXXABI::getArrayCookieSizeImpl(QualType elementType) {
// On ARM, the cookie is always:
// struct array_cookie {
// std::size_t element_size; // element_size != 0
@@ -936,7 +861,7 @@
// };
// TODO: what should we do if the allocated type actually wants
// greater alignment?
- return getContext().getTypeSizeInChars(getContext().getSizeType()) * 2;
+ return CharUnits::fromQuantity(2 * CGM.SizeSizeInBytes);
}
llvm::Value *ARMCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
@@ -944,7 +869,7 @@
llvm::Value *NumElements,
const CXXNewExpr *expr,
QualType ElementType) {
- assert(NeedsArrayCookie(expr));
+ assert(requiresArrayCookie(expr));
// NewPtr is a char*.
@@ -975,44 +900,18 @@
CookieSize.getQuantity());
}
-void ARMCXXABI::ReadArrayCookie(CodeGenFunction &CGF,
- llvm::Value *Ptr,
- const CXXDeleteExpr *expr,
- QualType ElementType,
- llvm::Value *&NumElements,
- llvm::Value *&AllocPtr,
- CharUnits &CookieSize) {
- // Derive a char* in the same address space as the pointer.
- unsigned AS = cast<llvm::PointerType>(Ptr->getType())->getAddressSpace();
- llvm::Type *CharPtrTy = CGF.Builder.getInt8Ty()->getPointerTo(AS);
-
- // If we don't need an array cookie, bail out early.
- if (!NeedsArrayCookie(expr, ElementType)) {
- AllocPtr = CGF.Builder.CreateBitCast(Ptr, CharPtrTy);
- NumElements = 0;
- CookieSize = CharUnits::Zero();
- return;
- }
-
- QualType SizeTy = getContext().getSizeType();
- CharUnits SizeSize = getContext().getTypeSizeInChars(SizeTy);
- llvm::Type *SizeLTy = CGF.ConvertType(SizeTy);
-
- // The cookie size is always 2 * sizeof(size_t).
- CookieSize = 2 * SizeSize;
-
- // The allocated pointer is the input ptr, minus that amount.
- AllocPtr = CGF.Builder.CreateBitCast(Ptr, CharPtrTy);
- AllocPtr = CGF.Builder.CreateConstInBoundsGEP1_64(AllocPtr,
- -CookieSize.getQuantity());
-
- // The number of elements is at offset sizeof(size_t) relative to that.
- llvm::Value *NumElementsPtr
- = CGF.Builder.CreateConstInBoundsGEP1_64(AllocPtr,
- SizeSize.getQuantity());
- NumElementsPtr =
- CGF.Builder.CreateBitCast(NumElementsPtr, SizeLTy->getPointerTo(AS));
- NumElements = CGF.Builder.CreateLoad(NumElementsPtr);
+llvm::Value *ARMCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
+ llvm::Value *allocPtr,
+ CharUnits cookieSize) {
+ // The number of elements is at offset sizeof(size_t) relative to
+ // the allocated pointer.
+ llvm::Value *numElementsPtr
+ = CGF.Builder.CreateConstInBoundsGEP1_64(allocPtr, CGF.SizeSizeInBytes);
+
+ unsigned AS = cast<llvm::PointerType>(allocPtr->getType())->getAddressSpace();
+ numElementsPtr =
+ CGF.Builder.CreateBitCast(numElementsPtr, CGF.SizeTy->getPointerTo(AS));
+ return CGF.Builder.CreateLoad(numElementsPtr);
}
/*********************** Static local initialization **************************/
@@ -1200,3 +1099,55 @@
CGF.EmitBlock(EndBlock);
}
+
+/// Register a global destructor using __cxa_atexit.
+static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
+ llvm::Constant *dtor,
+ llvm::Constant *addr) {
+ // We're assuming that the destructor function is something we can
+ // reasonably call with the default CC. Go ahead and cast it to the
+ // right prototype.
+ llvm::Type *dtorTy =
+ llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, false)->getPointerTo();
+
+ // extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
+ llvm::Type *paramTys[] = { dtorTy, CGF.Int8PtrTy, CGF.Int8PtrTy };
+ llvm::FunctionType *atexitTy =
+ llvm::FunctionType::get(CGF.IntTy, paramTys, false);
+
+ // Fetch the actual function.
+ llvm::Constant *atexit =
+ CGF.CGM.CreateRuntimeFunction(atexitTy, "__cxa_atexit");
+ if (llvm::Function *fn = dyn_cast<llvm::Function>(atexit))
+ fn->setDoesNotThrow();
+
+ // Create a variable that binds the atexit to this shared object.
+ llvm::Constant *handle =
+ CGF.CGM.CreateRuntimeVariable(CGF.Int8Ty, "__dso_handle");
+
+ llvm::Value *args[] = {
+ llvm::ConstantExpr::getBitCast(dtor, dtorTy),
+ llvm::ConstantExpr::getBitCast(addr, CGF.Int8PtrTy),
+ handle
+ };
+ CGF.Builder.CreateCall(atexit, args)->setDoesNotThrow();
+}
+
+/// Register a global destructor as best as we know how.
+void ItaniumCXXABI::registerGlobalDtor(CodeGenFunction &CGF,
+ llvm::Constant *dtor,
+ llvm::Constant *addr) {
+ // Use __cxa_atexit if available.
+ if (CGM.getCodeGenOpts().CXAAtExit) {
+ return emitGlobalDtorWithCXAAtExit(CGF, dtor, addr);
+ }
+
+ // In Apple kexts, we want to add a global destructor entry.
+ // FIXME: shouldn't this be guarded by some variable?
+ if (CGM.getContext().getLangOpts().AppleKext) {
+ // Generate a global destructor entry.
+ return CGM.AddCXXDtorEntry(dtor, addr);
+ }
+
+ CGF.registerGlobalDtorWithAtExit(dtor, addr);
+}
Modified: cfe/branches/tooling/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/MicrosoftCXXABI.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/MicrosoftCXXABI.cpp Tue May 8 03:47:31 2012
@@ -56,6 +56,11 @@
// TODO: 'for base' flag
}
+ void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
+ llvm::GlobalVariable *DeclPtr,
+ bool PerformInit);
+
+
// ==== Notes on array cookies =========
//
// MSVC seems to only use cookies when the class has a destructor; a
@@ -78,17 +83,88 @@
// delete[] p;
// }
// Whereas it prints "104" and "104" if you give A a destructor.
- void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
- const CXXDeleteExpr *expr,
- QualType ElementType, llvm::Value *&NumElements,
- llvm::Value *&AllocPtr, CharUnits &CookieSize) {
- CGF.CGM.ErrorUnsupported(expr, "don't know how to handle array cookies "
- "in the Microsoft C++ ABI");
- }
+
+ bool requiresArrayCookie(const CXXDeleteExpr *expr, QualType elementType);
+ bool requiresArrayCookie(const CXXNewExpr *expr);
+ CharUnits getArrayCookieSizeImpl(QualType type);
+ llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
+ llvm::Value *NewPtr,
+ llvm::Value *NumElements,
+ const CXXNewExpr *expr,
+ QualType ElementType);
+ llvm::Value *readArrayCookieImpl(CodeGenFunction &CGF,
+ llvm::Value *allocPtr,
+ CharUnits cookieSize);
};
}
+bool MicrosoftCXXABI::requiresArrayCookie(const CXXDeleteExpr *expr,
+ QualType elementType) {
+ // Microsoft seems to completely ignore the possibility of a
+ // two-argument usual deallocation function.
+ return elementType.isDestructedType();
+}
+
+bool MicrosoftCXXABI::requiresArrayCookie(const CXXNewExpr *expr) {
+ // Microsoft seems to completely ignore the possibility of a
+ // two-argument usual deallocation function.
+ return expr->getAllocatedType().isDestructedType();
+}
+
+CharUnits MicrosoftCXXABI::getArrayCookieSizeImpl(QualType type) {
+ // The array cookie is always a size_t; we then pad that out to the
+ // alignment of the element type.
+ ASTContext &Ctx = getContext();
+ return std::max(Ctx.getTypeSizeInChars(Ctx.getSizeType()),
+ Ctx.getTypeAlignInChars(type));
+}
+
+llvm::Value *MicrosoftCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
+ llvm::Value *allocPtr,
+ CharUnits cookieSize) {
+ unsigned AS = cast<llvm::PointerType>(allocPtr->getType())->getAddressSpace();
+ llvm::Value *numElementsPtr =
+ CGF.Builder.CreateBitCast(allocPtr, CGF.SizeTy->getPointerTo(AS));
+ return CGF.Builder.CreateLoad(numElementsPtr);
+}
+
+llvm::Value* MicrosoftCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
+ llvm::Value *newPtr,
+ llvm::Value *numElements,
+ const CXXNewExpr *expr,
+ QualType elementType) {
+ assert(requiresArrayCookie(expr));
+
+ // The size of the cookie.
+ CharUnits cookieSize = getArrayCookieSizeImpl(elementType);
+
+ // Compute an offset to the cookie.
+ llvm::Value *cookiePtr = newPtr;
+
+ // Write the number of elements into the appropriate slot.
+ unsigned AS = cast<llvm::PointerType>(newPtr->getType())->getAddressSpace();
+ llvm::Value *numElementsPtr
+ = CGF.Builder.CreateBitCast(cookiePtr, CGF.SizeTy->getPointerTo(AS));
+ CGF.Builder.CreateStore(numElements, numElementsPtr);
+
+ // Finally, compute a pointer to the actual data buffer by skipping
+ // over the cookie completely.
+ return CGF.Builder.CreateConstInBoundsGEP1_64(newPtr,
+ cookieSize.getQuantity());
+}
+
+void MicrosoftCXXABI::EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
+ llvm::GlobalVariable *DeclPtr,
+ bool PerformInit) {
+ // FIXME: this code was only tested for global initialization.
+ // Not sure whether we want thread-safe static local variables as VS
+ // doesn't make them thread-safe.
+
+ // Emit the initializer and add a global destructor if appropriate.
+ CGF.EmitCXXGlobalVarDeclInit(D, DeclPtr, PerformInit);
+}
+
CGCXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
return new MicrosoftCXXABI(CGM);
}
Modified: cfe/branches/tooling/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/CodeGen/TargetInfo.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/branches/tooling/lib/CodeGen/TargetInfo.cpp Tue May 8 03:47:31 2012
@@ -161,7 +161,7 @@
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i)
- if (!isEmptyField(Context, *i, AllowArrays))
+ if (!isEmptyField(Context, &*i, AllowArrays))
return false;
return true;
}
@@ -229,7 +229,7 @@
// Check for single element.
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
QualType FT = FD->getType();
// Ignore empty fields.
@@ -301,7 +301,7 @@
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
if (!is32Or64BitBasicType(FD->getType(), Context))
return false;
@@ -534,7 +534,7 @@
// passed in a register.
for (RecordDecl::field_iterator i = RT->getDecl()->field_begin(),
e = RT->getDecl()->field_end(); i != e; ++i) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
// Empty fields are ignored.
if (isEmptyField(Context, FD, true))
@@ -2540,7 +2540,7 @@
Members = 0;
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
uint64_t FldMembers;
if (!isHomogeneousAggregate(FD->getType(), Base, Context, &FldMembers))
return false;
@@ -2683,7 +2683,7 @@
unsigned idx = 0;
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i, ++idx) {
- const FieldDecl *FD = *i;
+ const FieldDecl *FD = &*i;
// Bit-fields are not addressable, we only need to verify they are "integer
// like". We still have to disallow a subsequent non-bitfield, for example:
@@ -3161,7 +3161,7 @@
// double fields.
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
i != e; ++i, ++idx) {
- const QualType Ty = (*i)->getType();
+ const QualType Ty = i->getType();
const BuiltinType *BT = Ty->getAs<BuiltinType>();
if (!BT || BT->getKind() != BuiltinType::Double)
@@ -3272,12 +3272,12 @@
if (FieldCnt && (FieldCnt <= 2) && !Layout.getFieldOffset(0)) {
RecordDecl::field_iterator b = RD->field_begin(), e = RD->field_end();
for (; b != e; ++b) {
- const BuiltinType *BT = (*b)->getType()->getAs<BuiltinType>();
+ const BuiltinType *BT = b->getType()->getAs<BuiltinType>();
if (!BT || !BT->isFloatingPoint())
break;
- RTList.push_back(CGT.ConvertType((*b)->getType()));
+ RTList.push_back(CGT.ConvertType(b->getType()));
}
if (b == e)
Removed: cfe/branches/tooling/lib/Driver/CC1Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/CC1Options.cpp?rev=156377&view=auto
==============================================================================
--- cfe/branches/tooling/lib/Driver/CC1Options.cpp (original)
+++ cfe/branches/tooling/lib/Driver/CC1Options.cpp (removed)
@@ -1,38 +0,0 @@
-//===--- CC1Options.cpp - Clang CC1 Options Table -------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Driver/CC1Options.h"
-#include "clang/Driver/Option.h"
-#include "clang/Driver/OptTable.h"
-using namespace clang;
-using namespace clang::driver;
-using namespace clang::driver::options;
-using namespace clang::driver::cc1options;
-
-static const OptTable::Info CC1InfoTable[] = {
-#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \
- HELPTEXT, METAVAR) \
- { NAME, HELPTEXT, METAVAR, Option::KIND##Class, PARAM, FLAGS, \
- OPT_##GROUP, OPT_##ALIAS },
-#include "clang/Driver/CC1Options.inc"
-};
-
-namespace {
-
-class CC1OptTable : public OptTable {
-public:
- CC1OptTable()
- : OptTable(CC1InfoTable, sizeof(CC1InfoTable) / sizeof(CC1InfoTable[0])) {}
-};
-
-}
-
-OptTable *clang::driver::createCC1OptTable() {
- return new CC1OptTable();
-}
Modified: cfe/branches/tooling/lib/Driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/CMakeLists.txt?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Driver/CMakeLists.txt (original)
+++ cfe/branches/tooling/lib/Driver/CMakeLists.txt Tue May 8 03:47:31 2012
@@ -4,7 +4,6 @@
Action.cpp
Arg.cpp
ArgList.cpp
- CC1Options.cpp
CC1AsOptions.cpp
Compilation.cpp
Driver.cpp
@@ -30,4 +29,4 @@
ENDIF(MSVC)
add_dependencies(clangDriver ClangAttrList ClangDiagnosticDriver
- ClangDriverOptions ClangCC1Options ClangCC1AsOptions)
+ ClangDriverOptions ClangCC1AsOptions)
Modified: cfe/branches/tooling/lib/Driver/Compilation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/Compilation.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Driver/Compilation.cpp (original)
+++ cfe/branches/tooling/lib/Driver/Compilation.cpp Tue May 8 03:47:31 2012
@@ -219,7 +219,7 @@
// to avoid emitting warnings about unused args.
OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
options::OPT_MMD };
- for (unsigned i = 0; i != sizeof(OutputOpts)/sizeof(OutputOpts[0]); ++i) {
+ for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
if (TranslatedArgs->hasArg(OutputOpts[i]))
TranslatedArgs->eraseArg(OutputOpts[i]);
}
Modified: cfe/branches/tooling/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/Driver.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Driver/Driver.cpp (original)
+++ cfe/branches/tooling/lib/Driver/Driver.cpp Tue May 8 03:47:31 2012
@@ -393,7 +393,12 @@
// Save the original job command(s).
std::string Cmd;
llvm::raw_string_ostream OS(Cmd);
- C.PrintJob(OS, C.getJobs(), "\n", false);
+ if (FailingCommand)
+ C.PrintJob(OS, *FailingCommand, "\n", false);
+ else
+ // Crash triggered by FORCE_CLANG_DIAGNOSTICS_CRASH, which doesn't have an
+ // associated FailingCommand, so just pass all jobs.
+ C.PrintJob(OS, C.getJobs(), "\n", false);
OS.flush();
// Clear stale state and suppress tool output.
@@ -489,10 +494,23 @@
Diag(clang::diag::note_drv_command_failed_diag_msg)
<< "Error generating run script: " + Script + " " + Err;
} else {
- // Strip -D, -F, and -I.
+ // Strip away options not necessary to reproduce the crash.
// FIXME: This doesn't work with quotes (e.g., -D "foo bar").
- std::string Flag[4] = {"-D ", "-F", "-I ", "-o "};
- for (unsigned i = 0; i < 4; ++i) {
+ SmallVector<std::string, 16> Flag;
+ Flag.push_back("-D ");
+ Flag.push_back("-F");
+ Flag.push_back("-I ");
+ Flag.push_back("-o ");
+ Flag.push_back("-coverage-file ");
+ Flag.push_back("-dependency-file ");
+ Flag.push_back("-fdebug-compilation-dir ");
+ Flag.push_back("-fmodule-cache-path ");
+ Flag.push_back("-include ");
+ Flag.push_back("-include-pch ");
+ Flag.push_back("-isysroot ");
+ Flag.push_back("-resource-dir ");
+ Flag.push_back("-serialize-diagnostic-file ");
+ for (unsigned i = 0, e = Flag.size(); i < e; ++i) {
size_t I = 0, E = 0;
do {
I = Cmd.find(Flag[i], I);
@@ -503,7 +521,19 @@
Cmd.erase(I, E - I + 1);
} while(1);
}
- // FIXME: Append the new filename with correct preprocessed suffix.
+ // Append the new filename with correct preprocessed suffix.
+ size_t I, E;
+ I = Cmd.find("-main-file-name ");
+ assert (I != std::string::npos && "Expected to find -main-file-name");
+ I += 16;
+ E = Cmd.find(" ", I);
+ assert (E != std::string::npos && "-main-file-name missing argument?");
+ StringRef OldFilename = StringRef(Cmd).slice(I, E);
+ StringRef NewFilename = llvm::sys::path::filename(*it);
+ I = StringRef(Cmd).rfind(OldFilename);
+ E = I + OldFilename.size();
+ I = Cmd.rfind(" ", I) + 1;
+ Cmd.replace(I, E - I, NewFilename.data(), NewFilename.size());
ScriptOS << Cmd;
Diag(clang::diag::note_drv_command_failed_diag_msg) << Script;
}
@@ -645,7 +675,7 @@
return false;
}
- if (C.getArgs().hasArg(options::OPT__help) ||
+ if (C.getArgs().hasArg(options::OPT_help) ||
C.getArgs().hasArg(options::OPT__help_hidden)) {
PrintHelp(C.getArgs().hasArg(options::OPT__help_hidden));
return false;
@@ -763,8 +793,7 @@
if (InputAction *IA = dyn_cast<InputAction>(A)) {
os << "\"" << IA->getInputArg().getValue(C.getArgs()) << "\"";
} else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) {
- os << '"' << (BIA->getArchName() ? BIA->getArchName() :
- C.getDefaultToolChain().getArchName()) << '"'
+ os << '"' << BIA->getArchName() << '"'
<< ", {" << PrintActions1(C, *BIA->begin(), Ids) << "}";
} else {
os << "{";
@@ -838,7 +867,7 @@
// When there is no explicit arch for this platform, make sure we still bind
// the architecture (to the default) so that -Xarch_ is handled correctly.
if (!Archs.size())
- Archs.push_back(0);
+ Archs.push_back(Args.MakeArgString(TC.getArchName()));
// FIXME: We killed off some others but these aren't yet detected in a
// functional manner. If we added information to jobs about which "auxiliary"
@@ -1347,10 +1376,13 @@
}
if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) {
- const ToolChain *TC = &C.getDefaultToolChain();
+ const ToolChain *TC;
+ const char *ArchName = BAA->getArchName();
- if (BAA->getArchName())
- TC = &getToolChain(C.getArgs(), BAA->getArchName());
+ if (ArchName)
+ TC = &getToolChain(C.getArgs(), ArchName);
+ else
+ TC = &C.getDefaultToolChain();
BuildJobsForAction(C, *BAA->begin(), TC, BAA->getArchName(),
AtTopLevel, LinkingOutput, Result);
Modified: cfe/branches/tooling/lib/Driver/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/OptTable.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Driver/OptTable.cpp (original)
+++ cfe/branches/tooling/lib/Driver/OptTable.cpp Tue May 8 03:47:31 2012
@@ -181,6 +181,8 @@
}
if (info.Flags & Unsupported)
Opt->setUnsupported(true);
+ if (info.Flags & CC1Option)
+ Opt->setIsCC1Option(true);
return Opt;
}
Modified: cfe/branches/tooling/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/ToolChains.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Driver/ToolChains.cpp (original)
+++ cfe/branches/tooling/lib/Driver/ToolChains.cpp Tue May 8 03:47:31 2012
@@ -287,76 +287,6 @@
getProgramPaths().push_back(Path);
}
-void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
- ArgStringList &CmdArgs) const {
- // The Clang toolchain uses explicit paths for internal libraries.
-
- // Unfortunately, we still might depend on a few of the libraries that are
- // only available in the gcc library directory (in particular
- // libstdc++.dylib). For now, hardcode the path to the known install location.
- // FIXME: This should get ripped out someday. However, when building on
- // 10.6 (darwin10), we're still relying on this to find libstdc++.dylib.
- llvm::sys::Path P(getDriver().Dir);
- P.eraseComponent(); // .../usr/bin -> ../usr
- P.appendComponent("llvm-gcc-4.2");
- P.appendComponent("lib");
- P.appendComponent("gcc");
- switch (getTriple().getArch()) {
- default:
- llvm_unreachable("Invalid Darwin arch!");
- case llvm::Triple::x86:
- case llvm::Triple::x86_64:
- P.appendComponent("i686-apple-darwin10");
- break;
- case llvm::Triple::arm:
- case llvm::Triple::thumb:
- P.appendComponent("arm-apple-darwin10");
- break;
- case llvm::Triple::ppc:
- case llvm::Triple::ppc64:
- P.appendComponent("powerpc-apple-darwin10");
- break;
- }
- P.appendComponent("4.2.1");
-
- // Determine the arch specific GCC subdirectory.
- const char *ArchSpecificDir = 0;
- switch (getTriple().getArch()) {
- default:
- break;
- case llvm::Triple::arm:
- case llvm::Triple::thumb: {
- std::string Triple = ComputeLLVMTriple(Args);
- StringRef TripleStr = Triple;
- if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5"))
- ArchSpecificDir = "v5";
- else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6"))
- ArchSpecificDir = "v6";
- else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7"))
- ArchSpecificDir = "v7";
- break;
- }
- case llvm::Triple::ppc64:
- ArchSpecificDir = "ppc64";
- break;
- case llvm::Triple::x86_64:
- ArchSpecificDir = "x86_64";
- break;
- }
-
- if (ArchSpecificDir) {
- P.appendComponent(ArchSpecificDir);
- bool Exists;
- if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
- CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
- P.eraseComponent();
- }
-
- bool Exists;
- if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
- CmdArgs.push_back(Args.MakeArgString("-L" + P.str()));
-}
-
void DarwinClang::AddLinkARCArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
@@ -956,7 +886,8 @@
// Add an explicit version min argument for the deployment target. We do this
// after argument translation because -Xarch_ arguments may add a version min
// argument.
- AddDeploymentTarget(*DAL);
+ if (BoundArch)
+ AddDeploymentTarget(*DAL);
// Validate the C++ standard library choice.
CXXStdlibType Type = GetCXXStdlibType(*DAL);
@@ -1218,6 +1149,11 @@
static const char *const MIPSELLibDirs[] = { "/lib" };
static const char *const MIPSELTriples[] = { "mipsel-linux-gnu" };
+ static const char *const MIPS64LibDirs[] = { "/lib64", "/lib" };
+ static const char *const MIPS64Triples[] = { "mips64-linux-gnu" };
+ static const char *const MIPS64ELLibDirs[] = { "/lib64", "/lib" };
+ static const char *const MIPS64ELTriples[] = { "mips64el-linux-gnu" };
+
static const char *const PPCLibDirs[] = { "/lib32", "/lib" };
static const char *const PPCTriples[] = {
"powerpc-linux-gnu",
@@ -1263,12 +1199,40 @@
MIPSLibDirs, MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs));
TripleAliases.append(
MIPSTriples, MIPSTriples + llvm::array_lengthof(MIPSTriples));
+ MultiarchLibDirs.append(
+ MIPS64LibDirs, MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs));
+ MultiarchTripleAliases.append(
+ MIPS64Triples, MIPS64Triples + llvm::array_lengthof(MIPS64Triples));
break;
case llvm::Triple::mipsel:
LibDirs.append(
MIPSELLibDirs, MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs));
TripleAliases.append(
MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples));
+ MultiarchLibDirs.append(
+ MIPS64ELLibDirs, MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs));
+ MultiarchTripleAliases.append(
+ MIPS64ELTriples, MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples));
+ break;
+ case llvm::Triple::mips64:
+ LibDirs.append(
+ MIPS64LibDirs, MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs));
+ TripleAliases.append(
+ MIPS64Triples, MIPS64Triples + llvm::array_lengthof(MIPS64Triples));
+ MultiarchLibDirs.append(
+ MIPSLibDirs, MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs));
+ MultiarchTripleAliases.append(
+ MIPSTriples, MIPSTriples + llvm::array_lengthof(MIPSTriples));
+ break;
+ case llvm::Triple::mips64el:
+ LibDirs.append(
+ MIPS64ELLibDirs, MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs));
+ TripleAliases.append(
+ MIPS64ELTriples, MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples));
+ MultiarchLibDirs.append(
+ MIPSELLibDirs, MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs));
+ MultiarchTripleAliases.append(
+ MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples));
break;
case llvm::Triple::ppc:
LibDirs.append(PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs));
@@ -1350,7 +1314,9 @@
// crtbegin.o without the subdirectory.
StringRef MultiarchSuffix
= (TargetArch == llvm::Triple::x86_64 ||
- TargetArch == llvm::Triple::ppc64) ? "/64" : "/32";
+ TargetArch == llvm::Triple::ppc64 ||
+ TargetArch == llvm::Triple::mips64 ||
+ TargetArch == llvm::Triple::mips64el) ? "/64" : "/32";
if (llvm::sys::fs::exists(LI->path() + MultiarchSuffix + "/crtbegin.o")) {
GCCMultiarchSuffix = MultiarchSuffix.str();
} else {
@@ -1830,6 +1796,7 @@
OpenSuse11_3,
OpenSuse11_4,
OpenSuse12_1,
+ OpenSuse12_2,
UbuntuHardy,
UbuntuIntrepid,
UbuntuJaunty,
@@ -1848,7 +1815,7 @@
}
static bool IsOpenSuse(enum LinuxDistro Distro) {
- return Distro >= OpenSuse11_3 && Distro <= OpenSuse12_1;
+ return Distro >= OpenSuse11_3 && Distro <= OpenSuse12_2;
}
static bool IsDebian(enum LinuxDistro Distro) {
@@ -1925,6 +1892,7 @@
.StartsWith("openSUSE 11.3", OpenSuse11_3)
.StartsWith("openSUSE 11.4", OpenSuse11_4)
.StartsWith("openSUSE 12.1", OpenSuse12_1)
+ .StartsWith("openSUSE 12.2", OpenSuse12_2)
.Default(UnknownDistro);
bool Exists;
Modified: cfe/branches/tooling/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/ToolChains.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Driver/ToolChains.h (original)
+++ cfe/branches/tooling/lib/Driver/ToolChains.h Tue May 8 03:47:31 2012
@@ -279,14 +279,6 @@
return TargetVersion < VersionTuple(V0, V1, V2);
}
- /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
- ///
- /// \param Args - The input argument list.
- /// \param CmdArgs [out] - The command argument list to append the paths
- /// (prefixed by -L) to.
- virtual void AddLinkSearchPathArgs(const ArgList &Args,
- ArgStringList &CmdArgs) const = 0;
-
/// AddLinkARCArgs - Add the linker arguments to link the ARC runtime library.
virtual void AddLinkARCArgs(const ArgList &Args,
ArgStringList &CmdArgs) const = 0;
@@ -333,7 +325,11 @@
return ToolChain::IsStrictAliasingDefault();
#endif
}
-
+
+ virtual bool IsMathErrnoDefault() const {
+ return false;
+ }
+
virtual bool IsObjCDefaultSynthPropertiesDefault() const {
return true;
}
@@ -392,9 +388,6 @@
/// @name Darwin ToolChain Implementation
/// {
- virtual void AddLinkSearchPathArgs(const ArgList &Args,
- ArgStringList &CmdArgs) const;
-
virtual void AddLinkRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const;
void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
@@ -459,6 +452,7 @@
public:
OpenBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args);
+ virtual bool IsMathErrnoDefault() const { return false; }
virtual bool IsObjCNonFragileABIDefault() const { return true; }
virtual bool IsObjCLegacyDispatchDefault() const {
llvm::Triple::ArchType Arch = getTriple().getArch();
@@ -477,6 +471,7 @@
public:
FreeBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args);
+ virtual bool IsMathErrnoDefault() const { return false; }
virtual bool IsObjCNonFragileABIDefault() const { return true; }
virtual bool IsObjCLegacyDispatchDefault() const {
llvm::Triple::ArchType Arch = getTriple().getArch();
@@ -495,6 +490,7 @@
public:
NetBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args);
+ virtual bool IsMathErrnoDefault() const { return false; }
virtual bool IsObjCNonFragileABIDefault() const { return true; }
virtual bool IsObjCLegacyDispatchDefault() const {
llvm::Triple::ArchType Arch = getTriple().getArch();
@@ -521,6 +517,8 @@
public:
DragonFly(const Driver &D, const llvm::Triple& Triple, const ArgList &Args);
+ virtual bool IsMathErrnoDefault() const { return false; }
+
virtual Tool &SelectTool(const Compilation &C, const JobAction &JA,
const ActionList &Inputs) const;
};
Modified: cfe/branches/tooling/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Driver/Tools.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Driver/Tools.cpp (original)
+++ cfe/branches/tooling/lib/Driver/Tools.cpp Tue May 8 03:47:31 2012
@@ -1617,9 +1617,8 @@
A->getOption().getID() != options::OPT_fhonor_nans)
CmdArgs.push_back("-menable-no-nans");
- // -fno-math-errno is default on Darwin. Other platforms, -fmath-errno is the
- // default.
- bool MathErrno = !getToolChain().getTriple().isOSDarwin();
+ // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
+ bool MathErrno = getToolChain().IsMathErrnoDefault();
if (Arg *A = Args.getLastArg(options::OPT_ffast_math,
options::OPT_fmath_errno,
options::OPT_fno_math_errno))
@@ -1817,6 +1816,8 @@
if (!A->getOption().matches(options::OPT_g0)) {
CmdArgs.push_back("-g");
}
+ if (Args.hasArg(options::OPT_gline_tables_only))
+ CmdArgs.push_back("-gline-tables-only");
Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections);
Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections);
@@ -2017,11 +2018,11 @@
if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
options::OPT_Wlarge_by_value_copy_def)) {
- CmdArgs.push_back("-Wlarge-by-value-copy");
- if (A->getNumValues())
- CmdArgs.push_back(A->getValue(Args));
- else
- CmdArgs.push_back("64"); // default value for -Wlarge-by-value-copy.
+ if (A->getNumValues()) {
+ StringRef bytes = A->getValue(Args);
+ CmdArgs.push_back(Args.MakeArgString("-Wlarge-by-value-copy=" + bytes));
+ } else
+ CmdArgs.push_back("-Wlarge-by-value-copy=64"); // default value
}
if (Args.hasArg(options::OPT__relocatable_pch))
@@ -2500,12 +2501,12 @@
// Honor -fpack-struct= and -fpack-struct, if given. Note that
// -fno-pack-struct doesn't apply to -fpack-struct=.
if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) {
- CmdArgs.push_back("-fpack-struct");
- CmdArgs.push_back(A->getValue(Args));
+ std::string PackStructStr = "-fpack-struct=";
+ PackStructStr += A->getValue(Args);
+ CmdArgs.push_back(Args.MakeArgString(PackStructStr));
} else if (Args.hasFlag(options::OPT_fpack_struct,
options::OPT_fno_pack_struct, false)) {
- CmdArgs.push_back("-fpack-struct");
- CmdArgs.push_back("1");
+ CmdArgs.push_back("-fpack-struct=1");
}
if (Args.hasArg(options::OPT_mkernel) ||
@@ -4034,9 +4035,6 @@
} else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
CmdArgs.push_back("-syslibroot");
CmdArgs.push_back(A->getValue(Args));
- } else if (getDarwinToolChain().isTargetIPhoneOS()) {
- CmdArgs.push_back("-syslibroot");
- CmdArgs.push_back("/Developer/SDKs/Extra");
}
Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
@@ -4211,8 +4209,6 @@
// This is more complicated in gcc...
CmdArgs.push_back("-lgomp");
- getDarwinToolChain().AddLinkSearchPathArgs(Args, CmdArgs);
-
if (isObjCRuntimeLinked(Args)) {
// Avoid linking compatibility stubs on i386 mac.
if (!getDarwinToolChain().isTargetMacOS() ||
Modified: cfe/branches/tooling/lib/Frontend/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Frontend/CMakeLists.txt?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Frontend/CMakeLists.txt (original)
+++ cfe/branches/tooling/lib/Frontend/CMakeLists.txt Tue May 8 03:47:31 2012
@@ -49,11 +49,10 @@
set_target_properties(clangFrontend PROPERTIES COMPILE_FLAGS ${NON_ANSI_COMPILE_FLAGS})
ENDIF(MSVC)
-add_dependencies(clangFrontend
+add_dependencies(clangFrontend
ClangAttrClasses
ClangAttrList
- ClangCC1Options
- ClangDiagnosticFrontend
+ ClangDiagnosticFrontend
ClangDiagnosticLex
ClangDiagnosticSema
ClangDriverOptions
Modified: cfe/branches/tooling/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Frontend/CompilerInstance.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/branches/tooling/lib/Frontend/CompilerInstance.cpp Tue May 8 03:47:31 2012
@@ -859,13 +859,6 @@
}
// Determine what file we're searching from.
- SourceManager &SourceMgr = getSourceManager();
- SourceLocation ExpandedImportLoc = SourceMgr.getExpansionLoc(ImportLoc);
- const FileEntry *CurFile
- = SourceMgr.getFileEntryForID(SourceMgr.getFileID(ExpandedImportLoc));
- if (!CurFile)
- CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
-
StringRef ModuleName = Path[0].first->getName();
SourceLocation ModuleNameLoc = Path[0].second;
Modified: cfe/branches/tooling/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Frontend/CompilerInvocation.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/branches/tooling/lib/Frontend/CompilerInvocation.cpp Tue May 8 03:47:31 2012
@@ -13,7 +13,7 @@
#include "clang/Basic/FileManager.h"
#include "clang/Driver/Arg.h"
#include "clang/Driver/ArgList.h"
-#include "clang/Driver/CC1Options.h"
+#include "clang/Driver/Options.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/OptTable.h"
#include "clang/Driver/Option.h"
@@ -181,8 +181,21 @@
}
static void CodeGenOptsToArgs(const CodeGenOptions &Opts, ToArgsList &Res) {
- if (Opts.DebugInfo)
- Res.push_back("-g");
+ switch (Opts.DebugInfo) {
+ case CodeGenOptions::NoDebugInfo:
+ break;
+ case CodeGenOptions::DebugLineTablesOnly:
+ Res.push_back("-gline-tables-only");
+ break;
+ case CodeGenOptions::LimitedDebugInfo:
+ Res.push_back("-g");
+ Res.push_back("-flimit-debug-info");
+ break;
+ case CodeGenOptions::FullDebugInfo:
+ Res.push_back("-g");
+ Res.push_back("-fno-limit-debug-info");
+ break;
+ }
if (Opts.DisableLLVMOpts)
Res.push_back("-disable-llvm-optzns");
if (Opts.DisableRedZone)
@@ -900,7 +913,7 @@
//===----------------------------------------------------------------------===//
using namespace clang::driver;
-using namespace clang::driver::cc1options;
+using namespace clang::driver::options;
//
@@ -909,14 +922,66 @@
unsigned DefaultOpt = 0;
if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable))
DefaultOpt = 2;
- // -Os/-Oz implies -O2
- return (Args.hasArg(OPT_Os) || Args.hasArg (OPT_Oz)) ? 2 :
- Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags);
+
+ if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+ if (A->getOption().matches(options::OPT_O0))
+ return 0;
+
+ assert (A->getOption().matches(options::OPT_O));
+
+ llvm::StringRef S(A->getValue(Args));
+ if (S == "s" || S == "z" || S.empty())
+ return 2;
+
+ return Args.getLastArgIntValue(OPT_O, DefaultOpt, Diags);
+ }
+
+ return DefaultOpt;
+}
+
+static unsigned getOptimizationLevelSize(ArgList &Args, InputKind IK,
+ DiagnosticsEngine &Diags) {
+ if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+ if (A->getOption().matches(options::OPT_O)) {
+ switch (A->getValue(Args)[0]) {
+ default:
+ return 0;
+ case 's':
+ return 1;
+ case 'z':
+ return 2;
+ }
+ }
+ }
+ return 0;
+}
+
+static void addWarningArgs(ArgList &Args, std::vector<std::string> &Warnings) {
+ for (arg_iterator I = Args.filtered_begin(OPT_W_Group),
+ E = Args.filtered_end(); I != E; ++I) {
+ Arg *A = *I;
+ // If the argument is a pure flag, add its name (minus the "-W" at the beginning)
+ // to the warning list. Else, add its value (for the OPT_W case).
+ if (A->getOption().getKind() == Option::FlagClass) {
+ Warnings.push_back(A->getOption().getName().substr(2));
+ } else {
+ for (unsigned Idx = 0, End = A->getNumValues();
+ Idx < End; ++Idx) {
+ StringRef V = A->getValue(Args, Idx);
+ // "-Wl," and such are not warning options.
+ // FIXME: Should be handled by putting these in separate flags.
+ if (V.startswith("l,") || V.startswith("a,") || V.startswith("p,"))
+ continue;
+
+ Warnings.push_back(V);
+ }
+ }
+ }
}
static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) {
- using namespace cc1options;
+ using namespace options;
bool Success = true;
if (Arg *A = Args.getLastArg(OPT_analyzer_store)) {
StringRef Name = A->getValue(Args);
@@ -1066,7 +1131,7 @@
static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
DiagnosticsEngine &Diags) {
- using namespace cc1options;
+ using namespace options;
bool Success = true;
unsigned OptLevel = getOptimizationLevel(Args, IK, Diags);
@@ -1083,12 +1148,18 @@
: CodeGenOptions::OnlyAlwaysInlining;
// -fno-inline-functions overrides OptimizationLevel > 1.
Opts.NoInline = Args.hasArg(OPT_fno_inline);
- Opts.Inlining = Args.hasArg(OPT_fno_inline_functions) ?
+ Opts.Inlining = Args.hasArg(OPT_fno_inline_functions) ?
CodeGenOptions::OnlyAlwaysInlining : Opts.Inlining;
- Opts.DebugInfo = Args.hasArg(OPT_g);
- Opts.LimitDebugInfo = !Args.hasArg(OPT_fno_limit_debug_info)
- || Args.hasArg(OPT_flimit_debug_info);
+ if (Args.hasArg(OPT_gline_tables_only)) {
+ Opts.DebugInfo = CodeGenOptions::DebugLineTablesOnly;
+ } else if (Args.hasArg(OPT_g_Flag)) {
+ if (Args.hasFlag(OPT_flimit_debug_info, OPT_fno_limit_debug_info, true))
+ Opts.DebugInfo = CodeGenOptions::LimitedDebugInfo;
+ else
+ Opts.DebugInfo = CodeGenOptions::FullDebugInfo;
+ }
+
Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
@@ -1099,8 +1170,7 @@
Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
Opts.NoCommon = Args.hasArg(OPT_fno_common);
Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
- Opts.OptimizeSize = Args.hasArg(OPT_Os);
- Opts.OptimizeSize = Args.hasArg(OPT_Oz) ? 2 : Opts.OptimizeSize;
+ Opts.OptimizeSize = getOptimizationLevelSize(Args, IK, Diags);
Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) ||
Args.hasArg(OPT_ffreestanding));
Opts.UnrollLoops = Args.hasArg(OPT_funroll_loops) ||
@@ -1185,7 +1255,7 @@
static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
ArgList &Args) {
- using namespace cc1options;
+ using namespace options;
Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file);
Opts.Targets = Args.getAllArgValues(OPT_MT);
Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps);
@@ -1198,7 +1268,7 @@
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
DiagnosticsEngine *Diags) {
- using namespace cc1options;
+ using namespace options;
bool Success = true;
Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file);
@@ -1295,16 +1365,7 @@
}
Opts.MessageLength = Args.getLastArgIntValue(OPT_fmessage_length, 0, Diags);
Opts.DumpBuildInformation = Args.getLastArgValue(OPT_dump_build_information);
-
- for (arg_iterator it = Args.filtered_begin(OPT_W),
- ie = Args.filtered_end(); it != ie; ++it) {
- StringRef V = (*it)->getValue(Args);
- // "-Wl," and such are not warnings options.
- if (V.startswith("l,") || V.startswith("a,") || V.startswith("p,"))
- continue;
-
- Opts.Warnings.push_back(V);
- }
+ addWarningArgs(Args, Opts.Warnings);
return Success;
}
@@ -1315,7 +1376,7 @@
static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) {
- using namespace cc1options;
+ using namespace options;
Opts.ProgramAction = frontend::ParseSyntaxOnly;
if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
switch (A->getOption().getID()) {
@@ -1535,7 +1596,7 @@
}
static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
- using namespace cc1options;
+ using namespace options;
Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/");
Opts.Verbose = Args.hasArg(OPT_v);
Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
@@ -1881,7 +1942,7 @@
Opts.ConstexprCallDepth = Args.getLastArgIntValue(OPT_fconstexpr_depth, 512,
Diags);
Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing);
- Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy,
+ Opts.NumLargeByValueCopy = Args.getLastArgIntValue(OPT_Wlarge_by_value_copy_EQ,
0, Diags);
Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields);
Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime);
@@ -1894,7 +1955,7 @@
Args.hasArg(OPT_fobjc_default_synthesize_properties);
Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior);
Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
- Opts.PackStruct = Args.getLastArgIntValue(OPT_fpack_struct, 0, Diags);
+ Opts.PackStruct = Args.getLastArgIntValue(OPT_fpack_struct_EQ, 0, Diags);
Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags);
Opts.PIELevel = Args.getLastArgIntValue(OPT_pie_level, 0, Diags);
Opts.Static = Args.hasArg(OPT_static_define);
@@ -1926,7 +1987,7 @@
// FIXME: Eliminate this dependency.
unsigned Opt = getOptimizationLevel(Args, IK, Diags);
Opts.Optimize = Opt != 0;
- Opts.OptimizeSize = Args.hasArg(OPT_Os) || Args.hasArg(OPT_Oz);
+ Opts.OptimizeSize = getOptimizationLevelSize(Args, IK, Diags);
// This is the __NO_INLINE__ define, which just depends on things like the
// optimization level and -fno-inline, not actually whether the backend has
@@ -1950,7 +2011,7 @@
static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
FileManager &FileMgr,
DiagnosticsEngine &Diags) {
- using namespace cc1options;
+ using namespace options;
Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch);
Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth);
if (const Arg *A = Args.getLastArg(OPT_token_cache))
@@ -2052,7 +2113,7 @@
static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
ArgList &Args) {
- using namespace cc1options;
+ using namespace options;
Opts.ShowCPP = !Args.hasArg(OPT_dM);
Opts.ShowComments = Args.hasArg(OPT_C);
Opts.ShowLineMarkers = !Args.hasArg(OPT_P);
@@ -2061,7 +2122,7 @@
}
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
- using namespace cc1options;
+ using namespace options;
Opts.ABI = Args.getLastArgValue(OPT_target_abi);
Opts.CXXABI = Args.getLastArgValue(OPT_cxx_abi);
Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
@@ -2083,7 +2144,7 @@
bool Success = true;
// Parse the arguments.
- OwningPtr<OptTable> Opts(createCC1OptTable());
+ OwningPtr<OptTable> Opts(createDriverOptTable());
unsigned MissingArgIndex, MissingArgCount;
OwningPtr<InputArgList> Args(
Opts->ParseArgs(ArgBegin, ArgEnd,MissingArgIndex, MissingArgCount));
@@ -2102,6 +2163,15 @@
Success = false;
}
+ // Issue errors on arguments that are not valid for CC1.
+ for (ArgList::iterator I = Args->begin(), E = Args->end();
+ I != E; ++I) {
+ if (!(*I)->getOption().isCC1Option()) {
+ Diags.Report(diag::err_drv_unknown_argument) << (*I)->getAsString(*Args);
+ Success = false;
+ }
+ }
+
Success = ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags) && Success;
Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success;
ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args);
Modified: cfe/branches/tooling/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Frontend/InitPreprocessor.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/branches/tooling/lib/Frontend/InitPreprocessor.cpp Tue May 8 03:47:31 2012
@@ -288,20 +288,16 @@
else if (!LangOpts.GNUMode && LangOpts.Digraphs)
Builder.defineMacro("__STDC_VERSION__", "199409L");
} else {
- if (LangOpts.GNUMode)
- Builder.defineMacro("__cplusplus");
- else {
- // C++0x [cpp.predefined]p1:
- // The name_ _cplusplus is defined to the value 201103L when compiling a
- // C++ translation unit.
- if (LangOpts.CPlusPlus0x)
- Builder.defineMacro("__cplusplus", "201103L");
- // C++03 [cpp.predefined]p1:
- // The name_ _cplusplus is defined to the value 199711L when compiling a
- // C++ translation unit.
- else
- Builder.defineMacro("__cplusplus", "199711L");
- }
+ // C++11 [cpp.predefined]p1:
+ // The name __cplusplus is defined to the value 201103L when compiling a
+ // C++ translation unit.
+ if (LangOpts.CPlusPlus0x)
+ Builder.defineMacro("__cplusplus", "201103L");
+ // C++03 [cpp.predefined]p1:
+ // The name __cplusplus is defined to the value 199711L when compiling a
+ // C++ translation unit.
+ else
+ Builder.defineMacro("__cplusplus", "199711L");
}
if (LangOpts.ObjC1)
@@ -501,6 +497,9 @@
if (!LangOpts.CharIsSigned)
Builder.defineMacro("__CHAR_UNSIGNED__");
+ if (!TargetInfo::isTypeSigned(TI.getWCharType()))
+ Builder.defineMacro("__WCHAR_UNSIGNED__");
+
if (!TargetInfo::isTypeSigned(TI.getWIntType()))
Builder.defineMacro("__WINT_UNSIGNED__");
Modified: cfe/branches/tooling/lib/Frontend/LayoutOverrideSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Frontend/LayoutOverrideSource.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Frontend/LayoutOverrideSource.cpp (original)
+++ cfe/branches/tooling/lib/Frontend/LayoutOverrideSource.cpp Tue May 8 03:47:31 2012
@@ -174,7 +174,7 @@
if (NumFields >= Known->second.FieldOffsets.size())
continue;
- FieldOffsets[*F] = Known->second.FieldOffsets[NumFields];
+ FieldOffsets[&*F] = Known->second.FieldOffsets[NumFields];
}
// Wrong number of fields.
Modified: cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/branches/tooling/lib/Frontend/TextDiagnostic.cpp Tue May 8 03:47:31 2012
@@ -40,7 +40,7 @@
/// \brief Number of spaces to indent when word-wrapping.
const unsigned WordWrapIndentation = 6;
-int bytesSincePreviousTabOrLineBegin(StringRef SourceLine, size_t i) {
+static int bytesSincePreviousTabOrLineBegin(StringRef SourceLine, size_t i) {
int bytes = 0;
while (0<i) {
if (SourceLine[--i]=='\t')
@@ -69,7 +69,7 @@
/// \param TabStop used to expand tabs
/// \return pair(printable text, 'true' iff original text was printable)
///
-std::pair<SmallString<16>,bool>
+static std::pair<SmallString<16>, bool>
printableTextForNextCharacter(StringRef SourceLine, size_t *i,
unsigned TabStop) {
assert(i && "i must not be null");
@@ -146,7 +146,7 @@
return std::make_pair(expandedByte, false);
}
-void expandTabs(std::string &SourceLine, unsigned TabStop) {
+static void expandTabs(std::string &SourceLine, unsigned TabStop) {
size_t i = SourceLine.size();
while (i>0) {
i--;
@@ -181,7 +181,7 @@
///
/// (\u3042 is represented in UTF-8 by three bytes and takes two columns to
/// display)
-void byteToColumn(StringRef SourceLine, unsigned TabStop,
+static void byteToColumn(StringRef SourceLine, unsigned TabStop,
SmallVectorImpl<int> &out) {
out.clear();
@@ -215,7 +215,7 @@
///
/// (\u3042 is represented in UTF-8 by three bytes and takes two columns to
/// display)
-void columnToByte(StringRef SourceLine, unsigned TabStop,
+static void columnToByte(StringRef SourceLine, unsigned TabStop,
SmallVectorImpl<int> &out) {
out.clear();
@@ -840,13 +840,10 @@
// Get information about the buffer it points into.
bool Invalid = false;
- StringRef BufData = SM.getBufferData(FID, &Invalid);
+ const char *BufStart = SM.getBufferData(FID, &Invalid).data();
if (Invalid)
return;
- const char *BufStart = BufData.data();
- const char *BufEnd = BufStart + BufData.size();
-
unsigned LineNo = SM.getLineNumber(FID, FileOffset);
unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
unsigned CaretEndColNo
@@ -860,7 +857,7 @@
// Compute the line end. Scan forward from the error position to the end of
// the line.
const char *LineEnd = TokPtr;
- while (*LineEnd != '\n' && *LineEnd != '\r' && LineEnd!=BufEnd)
+ while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
++LineEnd;
// FIXME: This shouldn't be necessary, but the CaretEndColNo can extend past
@@ -937,8 +934,7 @@
emitParseableFixits(Hints);
}
-void TextDiagnostic::emitSnippet(StringRef line)
-{
+void TextDiagnostic::emitSnippet(StringRef line) {
if (line.empty())
return;
@@ -952,8 +948,7 @@
= printableTextForNextCharacter(line, &i, DiagOpts.TabStop);
bool was_printable = res.second;
- if (DiagOpts.ShowColors
- && was_printable==print_reversed) {
+ if (DiagOpts.ShowColors && was_printable == print_reversed) {
if (print_reversed)
OS.reverseColor();
OS << to_print;
Modified: cfe/branches/tooling/lib/FrontendTool/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/FrontendTool/CMakeLists.txt?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/FrontendTool/CMakeLists.txt (original)
+++ cfe/branches/tooling/lib/FrontendTool/CMakeLists.txt Tue May 8 03:47:31 2012
@@ -1,4 +1,4 @@
-set(LLVM_USED_LIBS clangDriver clangFrontend clangRewrite clangCodeGen
+set(LLVM_USED_LIBS clangDriver clangFrontend clangRewrite clangCodeGen
clangStaticAnalyzerFrontend clangStaticAnalyzerCheckers clangStaticAnalyzerCore
clangARCMigrate)
@@ -7,5 +7,4 @@
)
add_dependencies(clangFrontendTool
- ClangCC1Options
ClangDiagnosticFrontend)
Modified: cfe/branches/tooling/lib/FrontendTool/ExecuteCompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
+++ cfe/branches/tooling/lib/FrontendTool/ExecuteCompilerInvocation.cpp Tue May 8 03:47:31 2012
@@ -16,7 +16,7 @@
#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
#include "clang/ARCMigrate/ARCMTActions.h"
#include "clang/CodeGen/CodeGenAction.h"
-#include "clang/Driver/CC1Options.h"
+#include "clang/Driver/Options.h"
#include "clang/Driver/OptTable.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/CompilerInstance.h"
@@ -129,7 +129,7 @@
bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
// Honor -help.
if (Clang->getFrontendOpts().ShowHelp) {
- OwningPtr<driver::OptTable> Opts(driver::createCC1OptTable());
+ OwningPtr<driver::OptTable> Opts(driver::createDriverOptTable());
Opts->PrintHelp(llvm::outs(), "clang -cc1",
"LLVM 'Clang' Compiler: http://clang.llvm.org");
return 0;
Modified: cfe/branches/tooling/lib/Headers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Headers/CMakeLists.txt?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Headers/CMakeLists.txt (original)
+++ cfe/branches/tooling/lib/Headers/CMakeLists.txt Tue May 8 03:47:31 2012
@@ -8,7 +8,6 @@
float.h
fma4intrin.h
immintrin.h
- intrin.h
iso646.h
limits.h
lzcntintrin.h
Modified: cfe/branches/tooling/lib/Headers/emmintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Headers/emmintrin.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Headers/emmintrin.h (original)
+++ cfe/branches/tooling/lib/Headers/emmintrin.h Tue May 8 03:47:31 2012
@@ -1186,7 +1186,10 @@
static __inline__ void __attribute__((__always_inline__, __nodebug__))
_mm_storel_epi64(__m128i *p, __m128i a)
{
- __builtin_ia32_storelv4si((__v2si *)p, a);
+ struct __mm_storel_epi64_struct {
+ long long u;
+ } __attribute__((__packed__, __may_alias__));
+ ((struct __mm_storel_epi64_struct*)p)->u = a[0];
}
static __inline__ void __attribute__((__always_inline__, __nodebug__))
Removed: cfe/branches/tooling/lib/Headers/intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Headers/intrin.h?rev=156377&view=auto
==============================================================================
--- cfe/branches/tooling/lib/Headers/intrin.h (original)
+++ cfe/branches/tooling/lib/Headers/intrin.h (removed)
@@ -1,368 +0,0 @@
-/*===---- intrin.h - Microsoft VS compatible X86 intrinsics -----------------===
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- *===-----------------------------------------------------------------------===
- */
-
-/* Unless we're compiling targeting MSVC platform, this header shouldn't even
- * *exist*. If there is a system header with the same name, defer to that,
- * etherwise produce an error for the user.
- */
-#ifndef _MSC_VER
-# if defined(__has_include_next) && __has_include_next(<intrin.h>)
-# include_next <intrin.h>
-# else
-# error The <intrin.h> builtin header is for use when targeting Windows and \
- provides MSVC compatible intrinsic declarations. It shouldn't be used \
- on non-Windows targets. Instead, see <x86intrin.h> which is supported \
- by Clang, GCC, and ICC on all platforms.
-# endif
-#else /* _MSC_VER */
-
-#ifndef __INTRIN_H
-#define __INTRIN_H
-
-/* These headers need to be provided by intrin.h in case users depend on any of
- * their contents. However, some of them are unavailable in freestanding
- * builds, so guard them appropriately.
- */
-#if __STDC_HOSTED__
-# include <crtdefs.h>
-# include <setjmp.h>
-#endif
-#include <stddef.h>
-
-/* Microsoft includes all of the intrinsics, and then restricts their
- * availability based on the particular target CPU; with Clang we rely on the
- * guarded includes used in our generic x86intrin header to pull in the
- * intrinsic declarations / definitions which should be available for the
- * target CPU variant.
- */
-#include <x86intrin.h>
-
-/* FIXME: We need to provide declarations for Microsoft-specific intrinsics in
- * addition to the chip-vendor intrinsics provided by x86intrin.h.
- *
- * The following is a list of the Microsoft-specific intrinsics that need
- * to be handled, separated by what header file they could be covered by.
- * However, some of these will require implementations not provided by other
- * header files. Please keep this list up to date as you implement any of the
- * intrinsics.
- *
- * malloc.h
- * void * __cdecl _alloca(size_t);
- *
- *
- * math.h
- * int __cdecl abs(int);
- * double ceil(double);
- * long __cdecl labs(long);
- *
- *
- * conio.h
- * int __cdecl _inp(unsigned short);
- * int __cdecl inp(unsigned short);
- * unsigned long __cdecl _inpd(unsigned short);
- * unsigned long __cdecl inpd(unsigned short);
- * unsigned short __cdecl _inpw(unsigned short);
- * unsigned short __cdecl inpw(unsigned short);
- * int __cdecl _outp(unsigned short,int);
- * int __cdecl outp(unsigned short,int);
- * unsigned long __cdecl _outpd(unsigned short,unsigned long);
- * unsigned long __cdecl outpd(unsigned short,unsigned long);
- * unsigned short __cdecl _outpw(unsigned short,unsigned short);
- * unsigned short __cdecl outpw(unsigned short,unsigned short);
- *
- *
- * setjmp.h
- * void __cdecl longjmp(jmp_buf, int);
- * int __cdecl _setjmp(jmp_buf);
- * int __cdecl _setjmpex(jmp_buf);
- *
- *
- * stdlib.h
- * unsigned long __cdecl _lrotl( unsigned long, int);
- * unsigned long __cdecl _lrotr( unsigned long, int);
- * unsigned int __cdecl _rotl( unsigned int, int);
- * unsigned int __cdecl _rotr( unsigned int, int);
- * unsigned __int64 __cdecl _rotl64( unsigned __int64, int);
- * unsigned __int64 __cdecl _rotr64( unsigned __int64, int);
- * __int64 __cdecl _abs64(__int64);
- *
- *
- * memory.h
- * int __cdecl memcmp(const void *,const void *, size_t);
- * void * __cdecl memcpy(void *,const void *, size_t);
- * void * __cdecl memset(void *, int, size_t);
- *
- *
- * string.h
- * int __cdecl strcmp(const char *, const char *);
- * size_t __cdecl strlen(const char *);
- * char * __cdecl strset(char *, int);
- * wchar_t * __cdecl wcscat(wchar_t *, * const wchar_t *);
- * int __cdecl wcscmp(const wchar_t *, * const wchar_t *);
- * wchar_t * __cdecl wcscpy(wchar_t *, * const wchar_t *);
- * size_t __cdecl wcslen(const wchar_t *);
- * wchar_t * __cdecl _wcsset(wchar_t *, wchar_t);
- *
- *
- * intrin.h
- * All Architectures:
- * unsigned short __cdecl _byteswap_ushort(unsigned short);
- * unsigned long __cdecl _byteswap_ulong(unsigned long);
- * unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
- * void __cdecl __debugbreak(void);
- *
- *
- * All Intel (x86, x64):
- * void __cdecl _disable(void);
- * __int64 __emul(int,int);
- * unsigned __int64 __emulu(unsigned int,unsigned int);
- * void __cdecl _enable(void);
- * long __cdecl _InterlockedDecrement(long volatile *);
- * long _InterlockedExchange(long volatile *, long);
- * short _InterlockedExchange16(short volatile *, short);
- * char _InterlockedExchange8(char volatile *, char);
- * long _InterlockedExchangeAdd(long volatile *, long);
- * short _InterlockedExchangeAdd16(short volatile *, short);
- * char _InterlockedExchangeAdd8(char volatile *, char);
- * long _InterlockedCompareExchange (long volatile *, long, long);
- * long __cdecl _InterlockedIncrement(long volatile *);
- * long _InterlockedOr(long volatile *, long);
- * char _InterlockedOr8(char volatile *, char);
- * short _InterlockedOr16(short volatile *, short);
- * long _InterlockedXor(long volatile *, long);
- * char _InterlockedXor8(char volatile *, char);
- * short _InterlockedXor16(short volatile *, short);
- * long _InterlockedAnd(long volatile *, long);
- * char _InterlockedAnd8(char volatile *, char);
- * short _InterlockedAnd16(short volatile *, short);
- * unsigned __int64 * __ll_lshift(unsigned __int64,int);
- * __int64 * __ll_rshift(__int64,int);
- * void * _ReturnAddress(void);
- * unsigned __int64 __ull_rshift(unsigned __int64,int);
- * void * _AddressOfReturnAddress(void);
- * void _WriteBarrier(void);
- * void _ReadWriteBarrier(void);
- * unsigned __int64 __rdtsc(void);
- * void __movsb(unsigned char *, unsigned char const *, size_t);
- * void __movsw(unsigned short *, unsigned short const *, size_t);
- * void __movsd(unsigned long *, unsigned long const *, size_t);
- * unsigned char __inbyte(unsigned short);
- * unsigned short __inword(unsigned short);
- * unsigned long __indword(unsigned short);
- * void __outbyte(unsigned short, unsigned char);
- * void __outword(unsigned short, unsigned short);
- * void __outdword(unsigned short, unsigned long);
- * void __inbytestring(unsigned short, unsigned char *, unsigned long);
- * void __inwordstring(unsigned short, unsigned short *, unsigned long);
- * void __indwordstring(unsigned short, unsigned long *, unsigned long);
- * void __outbytestring(unsigned short, unsigned char *, unsigned long);
- * void __outwordstring(unsigned short, unsigned short *, unsigned long);
- * void __outdwordstring(unsigned short, unsigned long *, unsigned long);
- * unsigned int __getcallerseflags();
- * void __vmx_vmptrst(unsigned __int64 *);
- * void __vmx_off(void);
- * void __svm_clgi(void);
- * void __svm_invlpga(void*, int);
- * void __svm_skinit(int);
- * void __svm_stgi(void);
- * void __svm_vmload(size_t);
- * void __svm_vmrun(size_t);
- * void __svm_vmsave(size_t);
- * void __halt(void);
- * void __sidt(void*);
- * void __lidt(void*);
- * void __ud2(void);
- * void __nop(void);
- * void __stosb(unsigned char *, unsigned char, size_t);
- * void __stosw(unsigned short *, unsigned short, size_t);
- * void __stosd(unsigned long *, unsigned long, size_t);
- * unsigned char _interlockedbittestandset(long volatile *, long);
- * unsigned char _interlockedbittestandreset(long volatile *, long);
- * void __cpuid(int[4], int);
- * void __cpuidex(int[4], int, int);
- * unsigned long __segmentlimit(unsigned long);
- * void __int2c(void);
- * char _InterlockedCompareExchange8(char volatile *, char, char);
- * unsigned short __lzcnt16(unsigned short);
- * unsigned int __lzcnt(unsigned int);
- * unsigned short __popcnt16(unsigned short);
- * unsigned int __popcnt(unsigned int);
- * __m128i _mm_extract_si64(__m128i,__m128i);
- * __m128i _mm_extracti_si64(__m128i, int, int);
- * __m128i _mm_insert_si64(__m128i,__m128i);
- * __m128i _mm_inserti_si64(__m128i, __m128i, int, int);
- * void _mm_stream_sd(double*,__m128d);
- * void _mm_stream_ss(float*,__m128);
- * unsigned __int64 __rdtscp(unsigned int*);
- *
- *
- * Intel x64 Only:
- * __int64 _InterlockedDecrement64(__int64 volatile *);
- * __int64 _InterlockedExchange64(__int64 volatile *, __int64);
- * void * _InterlockedExchangePointer(void * volatile *, void *);
- * __int64 _InterlockedExchangeAdd64(__int64 volatile *, __int64);
- * __int64 _InterlockedCompareExchange64(__int64 volatile *, __int64, __int64);
- * void *_InterlockedCompareExchangePointer (void * volatile *, void *, void *);
- * __int64 _InterlockedIncrement64(__int64 volatile *);
- * __int64 _InterlockedOr64(__int64 volatile *, __int64);
- * __int64 _InterlockedXor64(__int64 volatile *, __int64);
- * __int64 _InterlockedAnd64(__int64 volatile *, __int64);
- * void __faststorefence(void);
- * __int64 __mulh(__int64,__int64);
- * unsigned __int64 __umulh(unsigned __int64,unsigned __int64);
- * unsigned __int64 __readeflags(void);
- * void __writeeflags(unsigned __int64);
- * void __movsq(unsigned long long *, unsigned long long const *, size_t);
- * unsigned char __vmx_vmclear(unsigned __int64*);
- * unsigned char __vmx_vmlaunch(void);
- * unsigned char __vmx_vmptrld(unsigned __int64*);
- * unsigned char __vmx_vmread(size_t, size_t*);
- * unsigned char __vmx_vmresume(void);
- * unsigned char __vmx_vmwrite(size_t, size_t);
- * unsigned char __vmx_on(unsigned __int64*);
- * void __stosq(unsigned __int64 *, * unsigned __int64, size_t);
- * unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
- * unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
- * short _InterlockedCompareExchange16_np(short volatile *, short, short);
- * long _InterlockedCompareExchange_np (long volatile *, long, long);
- * __int64 _InterlockedCompareExchange64_np(__int64 volatile *, __int64, __int64);
- * void *_InterlockedCompareExchangePointer_np (void * volatile *, void *, void *);
- * unsigned char _InterlockedCompareExchange128(__int64 volatile *, __int64, __int64, __int64 *);
- * unsigned char _InterlockedCompareExchange128_np(__int64 volatile *, __int64, __int64, __int64 *);
- * long _InterlockedAnd_np(long volatile *, long);
- * char _InterlockedAnd8_np(char volatile *, char);
- * short _InterlockedAnd16_np(short volatile *, short);
- * __int64 _InterlockedAnd64_np(__int64 volatile *, __int64);
- * long _InterlockedOr_np(long volatile *, long);
- * char _InterlockedOr8_np(char volatile *, char);
- * short _InterlockedOr16_np(short volatile *, short);
- * __int64 _InterlockedOr64_np(__int64 volatile *, __int64);
- * long _InterlockedXor_np(long volatile *, long);
- * char _InterlockedXor8_np(char volatile *, char);
- * short _InterlockedXor16_np(short volatile *, short);
- * __int64 _InterlockedXor64_np(__int64 volatile *, __int64);
- * unsigned __int64 __lzcnt64(unsigned __int64);
- * unsigned __int64 __popcnt64(unsigned __int64);
- *
- *
- * Intel x86 Only:
- * long _InterlockedAddLargeStatistic(__int64 volatile *, long);
- * unsigned __readeflags(void);
- * void __writeeflags(unsigned);
- * void __addfsbyte(unsigned long, unsigned char);
- * void __addfsword(unsigned long, unsigned short);
- * void __addfsdword(unsigned long, unsigned long);
- * unsigned char __readfsbyte(unsigned long);
- * unsigned short __readfsword(unsigned long);
- * unsigned long __readfsdword(unsigned long);
- * unsigned __int64 __readfsqword(unsigned long);
- * void __writefsbyte(unsigned long, unsigned char);
- * void __writefsword(unsigned long, unsigned short);
- * void __writefsdword(unsigned long, unsigned long);
- * void __writefsqword(unsigned long, unsigned __int64);
- *
- *
- * Win64, 64-bit compilers only:
- * unsigned char _bittest(long const *, long);
- * unsigned char _bittestandset(long *, long);
- * unsigned char _bittestandreset(long *, long);
- * unsigned char _bittestandcomplement(long *, long);
- * unsigned char _bittest64(__int64 const *, __int64);
- * unsigned char _bittestandset64(__int64 *, __int64);
- * unsigned char _bittestandreset64(__int64 *, __int64);
- * unsigned char _bittestandcomplement64(__int64 *, __int64);
- * unsigned char _BitScanForward(unsigned long*, unsigned long);
- * unsigned char _BitScanReverse(unsigned long*, unsigned long);
- * unsigned char _BitScanForward64(unsigned long*, unsigned __int64);
- * unsigned char _BitScanReverse64(unsigned long*, unsigned __int64);
- * unsigned __int64 __shiftleft128(unsigned __int64, unsigned __int64, unsigned char);
- * unsigned __int64 __shiftright128(unsigned __int64, unsigned __int64, unsigned char);
- * unsigned __int64 _umul128(unsigned __int64, unsigned __int64, unsigned __int64 *);
- * __int64 _mul128(__int64, __int64, __int64 *);
- * void _ReadBarrier(void);
- * unsigned char _rotr8(unsigned char, unsigned char);
- * unsigned short _rotr16(unsigned short, unsigned char);
- * unsigned char _rotl8(unsigned char, unsigned char);
- * unsigned short _rotl16(unsigned short, unsigned char);
- * short _InterlockedIncrement16(short volatile *);
- * short _InterlockedDecrement16(short volatile *);
- * short _InterlockedCompareExchange16(short volatile *, short, short);
- *
- *
- * Kernel-Only:
- * unsigned __int64 __readcr0(void);
- * unsigned __int64 __readcr2(void);
- * unsigned __int64 __readcr3(void);
- * unsigned __int64 __readcr4(void);
- * unsigned __int64 __readcr8(void);
- * unsigned long __readcr0(void);
- * unsigned long __readcr2(void);
- * unsigned long __readcr3(void);
- * unsigned long __readcr4(void);
- * unsigned long __readcr8(void);
- * void __writecr0(unsigned __int64);
- * void __writecr3(unsigned __int64);
- * void __writecr4(unsigned __int64);
- * void __writecr8(unsigned __int64);
- * void __writecr0(unsigned);
- * void __writecr3(unsigned);
- * void __writecr4(unsigned);
- * void __writecr8(unsigned);
- * unsigned __int64 __readdr(unsigned int);
- * unsigned __readdr(unsigned int);
- * void __writedr(unsigned int, unsigned __int64);
- * void __writedr(unsigned int, unsigned);
- * void __wbinvd(void);
- * void __invlpg(void*);
- * unsigned __int64 __readmsr(unsigned long);
- * void __writemsr(unsigned long, unsigned __int64);
- * unsigned char __readgsbyte(unsigned long);
- * unsigned short __readgsword(unsigned long);
- * unsigned long __readgsdword(unsigned long);
- * unsigned __int64 __readgsqword(unsigned long);
- * void __writegsbyte(unsigned long, unsigned char);
- * void __writegsword(unsigned long, unsigned short);
- * void __writegsdword(unsigned long, unsigned long);
- * void __writegsqword(unsigned long, unsigned __int64);
- * void __incfsbyte(unsigned long);
- * void __incfsword(unsigned long);
- * void __incfsdword(unsigned long);
- * void __addgsbyte(unsigned long, unsigned char);
- * void __addgsword(unsigned long, unsigned short);
- * void __addgsdword(unsigned long, unsigned long);
- * void __addgsqword(unsigned long, unsigned __int64);
- * void __incgsbyte(unsigned long);
- * void __incgsword(unsigned long);
- * void __incgsdword(unsigned long);
- * void __incgsqword(unsigned long);
- * unsigned __int64 __readpmc(unsigned long);
- *
- *
- * Entirely Undocumented on MSDN:
- * void __nvreg_save_fence(void);
- * void __nvreg_restore_fence(void);
- */
-
-#endif /* __INTRIN_H */
-
-#endif /* _MSC_VER */
Modified: cfe/branches/tooling/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Lex/LiteralSupport.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/branches/tooling/lib/Lex/LiteralSupport.cpp Tue May 8 03:47:31 2012
@@ -1037,10 +1037,8 @@
void StringLiteralParser::init(const Token *StringToks, unsigned NumStringToks){
// The literal token may have come from an invalid source location (e.g. due
// to a PCH error), in which case the token length will be 0.
- if (NumStringToks == 0 || StringToks[0].getLength() < 2) {
- hadError = true;
- return;
- }
+ if (NumStringToks == 0 || StringToks[0].getLength() < 2)
+ return DiagnoseLexingError(SourceLocation());
// Scan all of the string portions, remember the max individual token length,
// computing a bound on the concatenated string length, and see whether any
@@ -1057,10 +1055,8 @@
// Implement Translation Phase #6: concatenation of string literals
/// (C99 5.1.1.2p1). The common case is only one string fragment.
for (unsigned i = 1; i != NumStringToks; ++i) {
- if (StringToks[i].getLength() < 2) {
- hadError = true;
- return;
- }
+ if (StringToks[i].getLength() < 2)
+ return DiagnoseLexingError(StringToks[i].getLocation());
// The string could be shorter than this if it needs cleaning, but this is a
// reasonable bound, which is all we need.
@@ -1123,10 +1119,8 @@
unsigned ThisTokLen =
Lexer::getSpelling(StringToks[i], ThisTokBuf, SM, Features,
&StringInvalid);
- if (StringInvalid) {
- hadError = true;
- continue;
- }
+ if (StringInvalid)
+ return DiagnoseLexingError(StringToks[i].getLocation());
const char *ThisTokBegin = ThisTokBuf;
const char *ThisTokEnd = ThisTokBuf+ThisTokLen;
@@ -1192,7 +1186,11 @@
if (DiagnoseBadString(StringToks[i]))
hadError = true;
} else {
- assert(ThisTokBuf[0] == '"' && "Expected quote, lexer broken?");
+ if (ThisTokBuf[0] != '"') {
+ // The file may have come from PCH and then changed after loading the
+ // PCH; Fail gracefully.
+ return DiagnoseLexingError(StringToks[i].getLocation());
+ }
++ThisTokBuf; // skip "
// Check if this is a pascal string
@@ -1349,6 +1347,12 @@
return !NoErrorOnBadEncoding;
}
+void StringLiteralParser::DiagnoseLexingError(SourceLocation Loc) {
+ hadError = true;
+ if (Diags)
+ Diags->Report(Loc, diag::err_lexing_string);
+}
+
/// getOffsetOfStringByte - This function returns the offset of the
/// specified byte of the string data represented by Token. This handles
/// advancing over escape sequences in the string.
Modified: cfe/branches/tooling/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseCXXInlineMethods.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseCXXInlineMethods.cpp Tue May 8 03:47:31 2012
@@ -16,6 +16,7 @@
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Scope.h"
#include "clang/AST/DeclTemplate.h"
+#include "RAIIObjectsForParser.h"
using namespace clang;
/// ParseCXXInlineMethodDef - We parsed and verified that the specified
@@ -348,77 +349,7 @@
LM.DefaultArgs[I].Toks = 0;
}
}
-
- // Parse a delayed exception-specification, if there is one.
- if (CachedTokens *Toks = LM.ExceptionSpecTokens) {
- // Save the current token position.
- SourceLocation origLoc = Tok.getLocation();
-
- // Parse the default argument from its saved token stream.
- Toks->push_back(Tok); // So that the current token doesn't get lost
- PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false);
-
- // Consume the previously-pushed token.
- ConsumeAnyToken();
-
- // C++11 [expr.prim.general]p3:
- // If a declaration declares a member function or member function
- // template of a class X, the expression this is a prvalue of type
- // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
- // and the end of the function-definition, member-declarator, or
- // declarator.
- CXXMethodDecl *Method;
- if (FunctionTemplateDecl *FunTmpl
- = dyn_cast<FunctionTemplateDecl>(LM.Method))
- Method = cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
- else
- Method = cast<CXXMethodDecl>(LM.Method);
-
- Sema::CXXThisScopeRAII ThisScope(Actions, Method->getParent(),
- Method->getTypeQualifiers(),
- getLangOpts().CPlusPlus0x);
-
- // Parse the exception-specification.
- SourceRange SpecificationRange;
- SmallVector<ParsedType, 4> DynamicExceptions;
- SmallVector<SourceRange, 4> DynamicExceptionRanges;
- ExprResult NoexceptExpr;
- CachedTokens *ExceptionSpecTokens;
-
- ExceptionSpecificationType EST
- = tryParseExceptionSpecification(/*Delayed=*/false, SpecificationRange,
- DynamicExceptions,
- DynamicExceptionRanges, NoexceptExpr,
- ExceptionSpecTokens);
-
- // Clean up the remaining tokens.
- if (Tok.is(tok::cxx_exceptspec_end))
- ConsumeToken();
- else if (EST != EST_None)
- Diag(Tok.getLocation(), diag::err_except_spec_unparsed);
- // Attach the exception-specification to the method.
- if (EST != EST_None)
- Actions.actOnDelayedExceptionSpecification(LM.Method, EST,
- SpecificationRange,
- DynamicExceptions,
- DynamicExceptionRanges,
- NoexceptExpr.isUsable()?
- NoexceptExpr.get() : 0);
-
- assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc,
- Tok.getLocation()) &&
- "tryParseExceptionSpecification went over the exception tokens!");
-
- // There could be leftover tokens (e.g. because of an error).
- // Skip through until we reach the original token position.
- while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof))
- ConsumeAnyToken();
-
- delete LM.ExceptionSpecTokens;
- LM.ExceptionSpecTokens = 0;
- }
-
PrototypeScope.Exit();
// Finish the delayed C++ method declaration.
Modified: cfe/branches/tooling/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseDecl.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseDecl.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseDecl.cpp Tue May 8 03:47:31 2012
@@ -14,6 +14,7 @@
#include "clang/Parse/Parser.h"
#include "clang/Parse/ParseDiagnostic.h"
#include "clang/Basic/OpenCL.h"
+#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/PrettyDeclStackTrace.h"
@@ -1311,10 +1312,9 @@
*DeclEnd = Tok.getLocation();
if (ExpectSemi &&
- ExpectAndConsume(tok::semi,
- Context == Declarator::FileContext
- ? diag::err_invalid_token_after_toplevel_declarator
- : diag::err_expected_semi_declaration)) {
+ ExpectAndConsumeSemi(Context == Declarator::FileContext
+ ? diag::err_invalid_token_after_toplevel_declarator
+ : diag::err_expected_semi_declaration)) {
// Okay, there was no semicolon and one was expected. If we see a
// declaration specifier, just assume it was missing and continue parsing.
// Otherwise things are very confused and we skip to recover.
@@ -1671,9 +1671,20 @@
}
if (TagName) {
+ IdentifierInfo *TokenName = Tok.getIdentifierInfo();
+ LookupResult R(Actions, TokenName, SourceLocation(),
+ Sema::LookupOrdinaryName);
+
Diag(Loc, diag::err_use_of_tag_name_without_tag)
- << Tok.getIdentifierInfo() << TagName << getLangOpts().CPlusPlus
- << FixItHint::CreateInsertion(Tok.getLocation(),FixitTagName);
+ << TokenName << TagName << getLangOpts().CPlusPlus
+ << FixItHint::CreateInsertion(Tok.getLocation(), FixitTagName);
+
+ if (Actions.LookupParsedName(R, getCurScope(), SS)) {
+ for (LookupResult::iterator I = R.begin(), IEnd = R.end();
+ I != IEnd; ++I)
+ Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
+ << TokenName << TagName;
+ }
// Parse this as a tag as if the missing tag were present.
if (TagKind == tok::kw_enum)
@@ -2549,7 +2560,7 @@
bool FirstDeclarator = true;
SourceLocation CommaLoc;
while (1) {
- ParsingDeclRAIIObject PD(*this);
+ ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent);
FieldDeclarator DeclaratorInfo(DS);
DeclaratorInfo.D.setCommaLoc(CommaLoc);
@@ -2762,12 +2773,16 @@
ScopedEnumKWLoc = ConsumeToken();
}
- // C++11 [temp.explicit]p12: The usual access controls do not apply to names
- // used to specify explicit instantiations. We extend this to also cover
- // explicit specializations.
- Sema::SuppressAccessChecksRAII SuppressAccess(Actions,
- TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
- TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
+ // C++11 [temp.explicit]p12:
+ // The usual access controls do not apply to names used to specify
+ // explicit instantiations.
+ // We extend this to also cover explicit specializations. Note that
+ // we don't suppress if this turns out to be an elaborated type
+ // specifier.
+ bool shouldDelayDiagsInTag =
+ (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
+ TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
+ SuppressAccessChecks diagsFromTag(*this, shouldDelayDiagsInTag);
// If attributes exist after tag, parse them.
ParsedAttributes attrs(AttrFactory);
@@ -2831,8 +2846,10 @@
IsScopedUsingClassTag = false;
}
- // Stop suppressing access control now we've parsed the enum name.
- SuppressAccess.done();
+ // Okay, end the suppression area. We'll decide whether to emit the
+ // diagnostics in a second.
+ if (shouldDelayDiagsInTag)
+ diagsFromTag.done();
TypeResult BaseType;
@@ -2914,16 +2931,29 @@
// enum foo {..}; void bar() { enum foo x; } <- use of old foo.
//
Sema::TagUseKind TUK;
- if (DS.isFriendSpecified())
- TUK = Sema::TUK_Friend;
- else if (!AllowDeclaration)
+ if (!AllowDeclaration) {
TUK = Sema::TUK_Reference;
- else if (Tok.is(tok::l_brace))
- TUK = Sema::TUK_Definition;
- else if (Tok.is(tok::semi) && DSC != DSC_type_specifier)
- TUK = Sema::TUK_Declaration;
- else
+ } else if (Tok.is(tok::l_brace)) {
+ if (DS.isFriendSpecified()) {
+ Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
+ << SourceRange(DS.getFriendSpecLoc());
+ ConsumeBrace();
+ SkipUntil(tok::r_brace);
+ TUK = Sema::TUK_Friend;
+ } else {
+ TUK = Sema::TUK_Definition;
+ }
+ } else if (Tok.is(tok::semi) && DSC != DSC_type_specifier) {
+ TUK = (DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration);
+ } else {
TUK = Sema::TUK_Reference;
+ }
+
+ // If this is an elaborated type specifier, and we delayed
+ // diagnostics before, just merge them into the current pool.
+ if (TUK == Sema::TUK_Reference && shouldDelayDiagsInTag) {
+ diagsFromTag.redelay();
+ }
MultiTemplateParamsArg TParams;
if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
@@ -3003,14 +3033,7 @@
}
if (Tok.is(tok::l_brace) && TUK != Sema::TUK_Reference) {
- if (TUK == Sema::TUK_Friend) {
- Diag(Tok, diag::err_friend_decl_defines_type)
- << SourceRange(DS.getFriendSpecLoc());
- ConsumeBrace();
- SkipUntil(tok::r_brace);
- } else {
- ParseEnumBody(StartLoc, TagDecl);
- }
+ ParseEnumBody(StartLoc, TagDecl);
}
if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc,
@@ -3056,7 +3079,7 @@
SourceLocation EqualLoc;
ExprResult AssignedVal;
- ParsingDeclRAIIObject PD(*this);
+ ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent);
if (Tok.is(tok::equal)) {
EqualLoc = ConsumeToken();
@@ -4197,7 +4220,6 @@
SmallVector<ParsedType, 2> DynamicExceptions;
SmallVector<SourceRange, 2> DynamicExceptionRanges;
ExprResult NoexceptExpr;
- CachedTokens *ExceptionSpecTokens = 0;
ParsedAttributes FnAttrs(AttrFactory);
ParsedType TrailingReturnType;
@@ -4264,20 +4286,12 @@
dyn_cast<CXXRecordDecl>(Actions.CurContext),
DS.getTypeQualifiers(),
IsCXX11MemberFunction);
-
+
// Parse exception-specification[opt].
- bool Delayed = (D.getContext() == Declarator::MemberContext &&
- D.getDeclSpec().getStorageClassSpec()
- != DeclSpec::SCS_typedef &&
- !D.getDeclSpec().isFriendSpecified());
- for (unsigned i = 0, e = D.getNumTypeObjects(); Delayed && i != e; ++i)
- Delayed &= D.getTypeObject(i).Kind == DeclaratorChunk::Paren;
- ESpecType = tryParseExceptionSpecification(Delayed,
- ESpecRange,
+ ESpecType = tryParseExceptionSpecification(ESpecRange,
DynamicExceptions,
DynamicExceptionRanges,
- NoexceptExpr,
- ExceptionSpecTokens);
+ NoexceptExpr);
if (ESpecType != EST_None)
EndLoc = ESpecRange.getEnd();
@@ -4312,7 +4326,6 @@
DynamicExceptions.size(),
NoexceptExpr.isUsable() ?
NoexceptExpr.get() : 0,
- ExceptionSpecTokens,
Tracker.getOpenLocation(),
EndLoc, D,
TrailingReturnType),
Modified: cfe/branches/tooling/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseDeclCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseDeclCXX.cpp Tue May 8 03:47:31 2012
@@ -968,9 +968,13 @@
// As an extension we do not perform access checking on the names used to
// specify explicit specializations either. This is important to allow
// specializing traits classes for private types.
- Sema::SuppressAccessChecksRAII SuppressAccess(Actions,
- TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
- TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
+ //
+ // Note that we don't suppress if this turns out to be an elaborated
+ // type specifier.
+ bool shouldDelayDiagsInTag =
+ (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
+ TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
+ SuppressAccessChecks diagsFromTag(*this, shouldDelayDiagsInTag);
ParsedAttributes attrs(AttrFactory);
// If attributes exist after tag, parse them.
@@ -1103,10 +1107,6 @@
}
}
- // As soon as we're finished parsing the class's template-id, turn access
- // checking back on.
- SuppressAccess.done();
-
// There are four options here.
// - If we are in a trailing return type, this is always just a reference,
// and we must not try to parse a definition. For instance,
@@ -1149,6 +1149,14 @@
else
TUK = Sema::TUK_Reference;
+ // If this is an elaborated type specifier, and we delayed
+ // diagnostics before, just merge them into the current pool.
+ if (shouldDelayDiagsInTag) {
+ diagsFromTag.done();
+ if (TUK == Sema::TUK_Reference)
+ diagsFromTag.redelay();
+ }
+
if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error ||
TUK != Sema::TUK_Definition)) {
if (DS.getTypeSpecType() != DeclSpec::TST_error) {
@@ -1535,34 +1543,16 @@
}
/// \brief If the given declarator has any parts for which parsing has to be
-/// delayed, e.g., default arguments or an exception-specification, create a
-/// late-parsed method declaration record to handle the parsing at the end of
-/// the class definition.
+/// delayed, e.g., default arguments, create a late-parsed method declaration
+/// record to handle the parsing at the end of the class definition.
void Parser::HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo,
Decl *ThisDecl) {
// We just declared a member function. If this member function
- // has any default arguments or an exception-specification, we'll need to
- // parse them later.
+ // has any default arguments, we'll need to parse them later.
LateParsedMethodDeclaration *LateMethod = 0;
DeclaratorChunk::FunctionTypeInfo &FTI
= DeclaratorInfo.getFunctionTypeInfo();
-
- // If there was a delayed exception-specification, hold onto its tokens.
- if (FTI.getExceptionSpecType() == EST_Delayed) {
- // Push this method onto the stack of late-parsed method
- // declarations.
- LateMethod = new LateParsedMethodDeclaration(this, ThisDecl);
- getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
- LateMethod->TemplateScope = getCurScope()->isTemplateParamScope();
-
- // Stash the exception-specification tokens in the late-pased mthod.
- LateMethod->ExceptionSpecTokens = FTI.ExceptionSpecTokens;
- FTI.ExceptionSpecTokens = 0;
- // Reserve space for the parameters.
- LateMethod->DefaultArgs.reserve(FTI.NumArgs);
- }
-
for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) {
if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) {
if (!LateMethod) {
@@ -1846,7 +1836,7 @@
// Parse the first declarator.
ParseDeclarator(DeclaratorInfo);
- // Error parsin g the declarator?
+ // Error parsing the declarator?
if (!DeclaratorInfo.hasName()) {
// If so, skip until the semi-colon or a }.
SkipUntil(tok::r_brace, true, true);
@@ -2065,7 +2055,7 @@
DeclsInGroup.push_back(ThisDecl);
}
- if (DeclaratorInfo.isFunctionDeclarator() &&
+ if (ThisDecl && DeclaratorInfo.isFunctionDeclarator() &&
DeclaratorInfo.getDeclSpec().getStorageClassSpec()
!= DeclSpec::SCS_typedef) {
HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
@@ -2358,7 +2348,7 @@
// C++11 [class.mem]p2:
// Within the class member-specification, the class is regarded as complete
- // within function bodies, default arguments, exception-specifications, and
+ // within function bodies, default arguments, and
// brace-or-equal-initializers for non-static data members (including such
// things in nested classes).
if (TagDecl && NonNestedClass) {
@@ -2559,63 +2549,13 @@
/// 'noexcept'
/// 'noexcept' '(' constant-expression ')'
ExceptionSpecificationType
-Parser::tryParseExceptionSpecification(bool Delayed,
+Parser::tryParseExceptionSpecification(
SourceRange &SpecificationRange,
SmallVectorImpl<ParsedType> &DynamicExceptions,
SmallVectorImpl<SourceRange> &DynamicExceptionRanges,
- ExprResult &NoexceptExpr,
- CachedTokens *&ExceptionSpecTokens) {
+ ExprResult &NoexceptExpr) {
ExceptionSpecificationType Result = EST_None;
- ExceptionSpecTokens = 0;
-
- // Handle delayed parsing of exception-specifications.
- if (Delayed) {
- if (Tok.isNot(tok::kw_throw) && Tok.isNot(tok::kw_noexcept))
- return EST_None;
-
- // Consume and cache the starting token.
- bool IsNoexcept = Tok.is(tok::kw_noexcept);
- Token StartTok = Tok;
- SpecificationRange = SourceRange(ConsumeToken());
-
- // Check for a '('.
- if (!Tok.is(tok::l_paren)) {
- // If this is a bare 'noexcept', we're done.
- if (IsNoexcept) {
- Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
- NoexceptExpr = 0;
- return EST_BasicNoexcept;
- }
-
- Diag(Tok, diag::err_expected_lparen_after) << "throw";
- return EST_DynamicNone;
- }
-
- // Cache the tokens for the exception-specification.
- ExceptionSpecTokens = new CachedTokens;
- ExceptionSpecTokens->push_back(StartTok); // 'throw' or 'noexcept'
- ExceptionSpecTokens->push_back(Tok); // '('
- SpecificationRange.setEnd(ConsumeParen()); // '('
-
- if (!ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
- /*StopAtSemi=*/true,
- /*ConsumeFinalToken=*/true)) {
- NoexceptExpr = 0;
- delete ExceptionSpecTokens;
- ExceptionSpecTokens = 0;
- return IsNoexcept? EST_BasicNoexcept : EST_DynamicNone;
- }
- SpecificationRange.setEnd(Tok.getLocation());
-
- // Add the 'stop' token.
- Token End;
- End.startToken();
- End.setKind(tok::cxx_exceptspec_end);
- End.setLocation(Tok.getLocation());
- ExceptionSpecTokens->push_back(End);
- return EST_Delayed;
- }
-
+
// See if there's a dynamic specification.
if (Tok.is(tok::kw_throw)) {
Result = ParseDynamicExceptionSpecification(SpecificationRange,
@@ -2938,28 +2878,30 @@
}
bool AttrParsed = false;
- // No scoped names are supported; ideally we could put all non-standard
- // attributes into namespaces.
- if (!ScopeName) {
- switch (AttributeList::getKind(AttrName)) {
- // No arguments
- case AttributeList::AT_carries_dependency:
- case AttributeList::AT_noreturn: {
- if (Tok.is(tok::l_paren)) {
- Diag(Tok.getLocation(), diag::err_cxx11_attribute_forbids_arguments)
- << AttrName->getName();
- break;
- }
-
- attrs.addNew(AttrName, AttrLoc, 0, AttrLoc, 0,
- SourceLocation(), 0, 0, false, true);
- AttrParsed = true;
+ switch (AttributeList::getKind(AttrName, ScopeName)) {
+ // No arguments
+ case AttributeList::AT_carries_dependency:
+ // FIXME: implement generic support of attributes with C++11 syntax
+ // see Parse/ParseDecl.cpp: ParseGNUAttributes
+ case AttributeList::AT_clang___fallthrough:
+ case AttributeList::AT_noreturn: {
+ if (Tok.is(tok::l_paren)) {
+ Diag(Tok.getLocation(), diag::err_cxx11_attribute_forbids_arguments)
+ << AttrName->getName();
break;
}
- // Silence warnings
- default: break;
- }
+ attrs.addNew(AttrName,
+ SourceRange(ScopeLoc.isValid() ? ScopeLoc : AttrLoc,
+ AttrLoc),
+ ScopeName, ScopeLoc, 0,
+ SourceLocation(), 0, 0, false, true);
+ AttrParsed = true;
+ break;
+ }
+
+ // Silence warnings
+ default: break;
}
// Skip the entire parameter clause, if any
Modified: cfe/branches/tooling/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseExpr.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseExpr.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseExpr.cpp Tue May 8 03:47:31 2012
@@ -2392,7 +2392,7 @@
SourceLocation(),
EST_None,
SourceLocation(),
- 0, 0, 0, 0, 0,
+ 0, 0, 0, 0,
CaretLoc, CaretLoc,
ParamInfo),
attrs, CaretLoc);
Modified: cfe/branches/tooling/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseExprCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseExprCXX.cpp Tue May 8 03:47:31 2012
@@ -780,13 +780,10 @@
llvm::SmallVector<ParsedType, 2> DynamicExceptions;
llvm::SmallVector<SourceRange, 2> DynamicExceptionRanges;
ExprResult NoexceptExpr;
- CachedTokens *ExceptionSpecTokens;
- ESpecType = tryParseExceptionSpecification(/*Delayed=*/false,
- ESpecRange,
+ ESpecType = tryParseExceptionSpecification(ESpecRange,
DynamicExceptions,
DynamicExceptionRanges,
- NoexceptExpr,
- ExceptionSpecTokens);
+ NoexceptExpr);
if (ESpecType != EST_None)
DeclEndLoc = ESpecRange.getEnd();
@@ -821,7 +818,6 @@
DynamicExceptions.size(),
NoexceptExpr.isUsable() ?
NoexceptExpr.get() : 0,
- 0,
DeclLoc, DeclEndLoc, D,
TrailingReturnType),
Attr, DeclEndLoc);
@@ -867,7 +863,6 @@
/*ExceptionRanges=*/0,
/*NumExceptions=*/0,
/*NoexceptExpr=*/0,
- /*ExceptionSpecTokens=*/0,
DeclLoc, DeclEndLoc, D,
TrailingReturnType),
Attr, DeclEndLoc);
Modified: cfe/branches/tooling/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseObjc.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseObjc.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseObjc.cpp Tue May 8 03:47:31 2012
@@ -965,7 +965,7 @@
tok::TokenKind mType,
tok::ObjCKeywordKind MethodImplKind,
bool MethodDefinition) {
- ParsingDeclRAIIObject PD(*this);
+ ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent);
if (Tok.is(tok::code_completion)) {
Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus,
Modified: cfe/branches/tooling/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseStmt.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseStmt.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseStmt.cpp Tue May 8 03:47:31 2012
@@ -771,7 +771,7 @@
DeclsInGroup.data(), DeclsInGroup.size());
StmtResult R = Actions.ActOnDeclStmt(Res, LabelLoc, Tok.getLocation());
- ExpectAndConsume(tok::semi, diag::err_expected_semi_declaration);
+ ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
if (R.isUsable())
Stmts.push_back(R.release());
}
@@ -895,6 +895,16 @@
// Otherwise the condition is valid or the rparen is present.
T.consumeClose();
+
+ // Check for extraneous ')'s to catch things like "if (foo())) {". We know
+ // that all callers are looking for a statement after the condition, so ")"
+ // isn't valid.
+ while (Tok.is(tok::r_paren)) {
+ Diag(Tok, diag::err_extraneous_rparen_in_condition)
+ << FixItHint::CreateRemoval(Tok.getLocation());
+ ConsumeParen();
+ }
+
return false;
}
Modified: cfe/branches/tooling/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseTemplate.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseTemplate.cpp Tue May 8 03:47:31 2012
@@ -90,7 +90,8 @@
// Tell the action that names should be checked in the context of
// the declaration to come.
- ParsingDeclRAIIObject ParsingTemplateParams(*this);
+ ParsingDeclRAIIObject
+ ParsingTemplateParams(*this, ParsingDeclRAIIObject::NoParent);
// Parse multiple levels of template headers within this template
// parameter scope, e.g.,
@@ -213,10 +214,11 @@
return ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
prefixAttrs);
- // Parse the declaration specifiers, stealing the accumulated
- // diagnostics from the template parameters.
+ // Parse the declaration specifiers, stealing any diagnostics from
+ // the template parameters.
ParsingDeclSpec DS(*this, &DiagsFromTParams);
+ // Move the attributes from the prefix into the DS.
DS.takeAttributesFrom(prefixAttrs);
ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
@@ -259,7 +261,7 @@
}
// Eat the semi colon after the declaration.
- ExpectAndConsume(tok::semi, diag::err_expected_semi_declaration);
+ ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
if (LateParsedAttrs.size() > 0)
ParseLexedAttributeList(LateParsedAttrs, ThisDecl, true, false);
DeclaratorInfo.complete(ThisDecl);
@@ -652,6 +654,7 @@
// end of the template-parameter-list rather than a greater-than
// operator.
GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+ EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated);
DefaultArg = ParseAssignmentExpression();
if (DefaultArg.isInvalid())
@@ -1131,7 +1134,8 @@
SourceLocation &DeclEnd,
AccessSpecifier AS) {
// This isn't really required here.
- ParsingDeclRAIIObject ParsingTemplateParams(*this);
+ ParsingDeclRAIIObject
+ ParsingTemplateParams(*this, ParsingDeclRAIIObject::NoParent);
return ParseSingleDeclarationAfterTemplate(Context,
ParsedTemplateInfo(ExternLoc,
Modified: cfe/branches/tooling/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/ParseTentative.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/ParseTentative.cpp (original)
+++ cfe/branches/tooling/lib/Parse/ParseTentative.cpp Tue May 8 03:47:31 2012
@@ -933,8 +933,7 @@
return TPResult::Error();
if (Tok.is(tok::identifier)) {
const Token &Next = NextToken();
- bool NotObjC = !(getLangOpts().ObjC1 || getLangOpts().ObjC2);
- return (NotObjC && Next.is(tok::identifier)) ?
+ return (!getLangOpts().ObjC1 && Next.is(tok::identifier)) ?
TPResult::True() : TPResult::False();
}
return isCXXDeclarationSpecifier(BracedCastResult);
Modified: cfe/branches/tooling/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/Parser.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/Parser.cpp (original)
+++ cfe/branches/tooling/lib/Parse/Parser.cpp Tue May 8 03:47:31 2012
@@ -185,7 +185,7 @@
bool Parser::ExpectAndConsumeSemi(unsigned DiagID) {
if (Tok.is(tok::semi) || Tok.is(tok::code_completion)) {
- ConsumeAnyToken();
+ ConsumeToken();
return false;
}
@@ -1130,10 +1130,7 @@
ParseDeclarator(ParmDeclarator);
}
- if (Tok.is(tok::semi)) {
- ConsumeToken();
- } else {
- Diag(Tok, diag::err_expected_semi_declaration);
+ if (ExpectAndConsumeSemi(diag::err_expected_semi_declaration)) {
// Skip to end of block or statement
SkipUntil(tok::semi, true);
if (Tok.is(tok::semi))
Modified: cfe/branches/tooling/lib/Parse/RAIIObjectsForParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Parse/RAIIObjectsForParser.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Parse/RAIIObjectsForParser.h (original)
+++ cfe/branches/tooling/lib/Parse/RAIIObjectsForParser.h Tue May 8 03:47:31 2012
@@ -16,13 +16,208 @@
#define LLVM_CLANG_PARSE_RAII_OBJECTS_FOR_PARSER_H
#include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/DelayedDiagnostic.h"
+#include "clang/Sema/Sema.h"
namespace clang {
- // TODO: move ParsingDeclRAIIObject here.
// TODO: move ParsingClassDefinition here.
// TODO: move TentativeParsingAction here.
-
-
+
+ /// \brief A RAII object used to temporarily suppress access-like
+ /// checking. Access-like checks are those associated with
+ /// controlling the use of a declaration, like C++ access control
+ /// errors and deprecation warnings. They are contextually
+ /// dependent, in that they can only be resolved with full
+ /// information about what's being declared. They are also
+ /// suppressed in certain contexts, like the template arguments of
+ /// an explicit instantiation. However, those suppression contexts
+ /// cannot necessarily be fully determined in advance; for
+ /// example, something starting like this:
+ /// template <> class std::vector<A::PrivateType>
+ /// might be the entirety of an explicit instantiation:
+ /// template <> class std::vector<A::PrivateType>;
+ /// or just an elaborated type specifier:
+ /// template <> class std::vector<A::PrivateType> make_vector<>();
+ /// Therefore this class collects all the diagnostics and permits
+ /// them to be re-delayed in a new context.
+ class SuppressAccessChecks {
+ Sema &S;
+ sema::DelayedDiagnosticPool DiagnosticPool;
+ Sema::ParsingDeclState State;
+ bool Active;
+
+ public:
+ /// Begin suppressing access-like checks
+ SuppressAccessChecks(Parser &P, bool activate = true)
+ : S(P.getActions()), DiagnosticPool(NULL) {
+ if (activate) {
+ State = S.PushParsingDeclaration(DiagnosticPool);
+ Active = true;
+ } else {
+ Active = false;
+ }
+ }
+
+ void done() {
+ assert(Active && "trying to end an inactive suppression");
+ S.PopParsingDeclaration(State, NULL);
+ Active = false;
+ }
+
+ void redelay() {
+ assert(!Active && "redelaying without having ended first");
+ if (!DiagnosticPool.pool_empty())
+ S.redelayDiagnostics(DiagnosticPool);
+ assert(DiagnosticPool.pool_empty());
+ }
+
+ ~SuppressAccessChecks() {
+ if (Active) done();
+ }
+ };
+
+ /// \brief RAII object used to inform the actions that we're
+ /// currently parsing a declaration. This is active when parsing a
+ /// variable's initializer, but not when parsing the body of a
+ /// class or function definition.
+ class ParsingDeclRAIIObject {
+ Sema &Actions;
+ sema::DelayedDiagnosticPool DiagnosticPool;
+ Sema::ParsingDeclState State;
+ bool Popped;
+
+ // Do not implement.
+ ParsingDeclRAIIObject(const ParsingDeclRAIIObject &other);
+ ParsingDeclRAIIObject &operator=(const ParsingDeclRAIIObject &other);
+
+ public:
+ enum NoParent_t { NoParent };
+ ParsingDeclRAIIObject(Parser &P, NoParent_t _)
+ : Actions(P.getActions()), DiagnosticPool(NULL) {
+ push();
+ }
+
+ /// Creates a RAII object whose pool is optionally parented by another.
+ ParsingDeclRAIIObject(Parser &P,
+ const sema::DelayedDiagnosticPool *parentPool)
+ : Actions(P.getActions()), DiagnosticPool(parentPool) {
+ push();
+ }
+
+ /// Creates a RAII object and, optionally, initialize its
+ /// diagnostics pool by stealing the diagnostics from another
+ /// RAII object (which is assumed to be the current top pool).
+ ParsingDeclRAIIObject(Parser &P, ParsingDeclRAIIObject *other)
+ : Actions(P.getActions()),
+ DiagnosticPool(other ? other->DiagnosticPool.getParent() : NULL) {
+ if (other) {
+ DiagnosticPool.steal(other->DiagnosticPool);
+ other->abort();
+ }
+ push();
+ }
+
+ ~ParsingDeclRAIIObject() {
+ abort();
+ }
+
+ sema::DelayedDiagnosticPool &getDelayedDiagnosticPool() {
+ return DiagnosticPool;
+ }
+ const sema::DelayedDiagnosticPool &getDelayedDiagnosticPool() const {
+ return DiagnosticPool;
+ }
+
+ /// Resets the RAII object for a new declaration.
+ void reset() {
+ abort();
+ push();
+ }
+
+ /// Signals that the context was completed without an appropriate
+ /// declaration being parsed.
+ void abort() {
+ pop(0);
+ }
+
+ void complete(Decl *D) {
+ assert(!Popped && "ParsingDeclaration has already been popped!");
+ pop(D);
+ }
+
+ /// Unregister this object from Sema, but remember all the
+ /// diagnostics that were emitted into it.
+ void abortAndRemember() {
+ pop(0);
+ }
+
+ private:
+ void push() {
+ State = Actions.PushParsingDeclaration(DiagnosticPool);
+ Popped = false;
+ }
+
+ void pop(Decl *D) {
+ if (!Popped) {
+ Actions.PopParsingDeclaration(State, D);
+ Popped = true;
+ }
+ }
+ };
+
+ /// A class for parsing a DeclSpec.
+ class ParsingDeclSpec : public DeclSpec {
+ ParsingDeclRAIIObject ParsingRAII;
+
+ public:
+ ParsingDeclSpec(Parser &P)
+ : DeclSpec(P.getAttrFactory()),
+ ParsingRAII(P, ParsingDeclRAIIObject::NoParent) {}
+ ParsingDeclSpec(Parser &P, ParsingDeclRAIIObject *RAII)
+ : DeclSpec(P.getAttrFactory()),
+ ParsingRAII(P, RAII) {}
+
+ const sema::DelayedDiagnosticPool &getDelayedDiagnosticPool() const {
+ return ParsingRAII.getDelayedDiagnosticPool();
+ }
+
+ void complete(Decl *D) {
+ ParsingRAII.complete(D);
+ }
+
+ void abort() {
+ ParsingRAII.abort();
+ }
+ };
+
+ /// A class for parsing a declarator.
+ class ParsingDeclarator : public Declarator {
+ ParsingDeclRAIIObject ParsingRAII;
+
+ public:
+ ParsingDeclarator(Parser &P, const ParsingDeclSpec &DS, TheContext C)
+ : Declarator(DS, C), ParsingRAII(P, &DS.getDelayedDiagnosticPool()) {
+ }
+
+ const ParsingDeclSpec &getDeclSpec() const {
+ return static_cast<const ParsingDeclSpec&>(Declarator::getDeclSpec());
+ }
+
+ ParsingDeclSpec &getMutableDeclSpec() const {
+ return const_cast<ParsingDeclSpec&>(getDeclSpec());
+ }
+
+ void clear() {
+ Declarator::clear();
+ ParsingRAII.reset();
+ }
+
+ void complete(Decl *D) {
+ ParsingRAII.complete(D);
+ }
+ };
+
/// ExtensionRAIIObject - This saves the state of extension warnings when
/// constructed and disables them. When destructed, it restores them back to
/// the way they used to be. This is used to handle __extension__ in the
Modified: cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/branches/tooling/lib/Rewrite/RewriteModernObjC.cpp Tue May 8 03:47:31 2012
@@ -109,7 +109,7 @@
llvm::SmallPtrSet<ObjCInterfaceDecl*, 8> ObjCSynthesizedStructs;
llvm::SmallPtrSet<ObjCProtocolDecl*, 8> ObjCSynthesizedProtocols;
llvm::SmallPtrSet<ObjCInterfaceDecl*, 8> ObjCWrittenInterfaces;
- llvm::SmallPtrSet<TagDecl*, 8> TagsDefinedInIvarDecls;
+ llvm::SmallPtrSet<TagDecl*, 32> GlobalDefinedTags;
SmallVector<ObjCInterfaceDecl*, 32> ObjCInterfacesSeen;
/// DefinedNonLazyClasses - List of defined "non-lazy" classes.
SmallVector<ObjCInterfaceDecl*, 8> DefinedNonLazyClasses;
@@ -346,6 +346,10 @@
std::string &Result);
void RewriteObjCFieldDecl(FieldDecl *fieldDecl, std::string &Result);
+ bool IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, TagDecl *Tag,
+ bool &IsNamedDefinition);
+ void RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl,
+ std::string &Result);
bool RewriteObjCFieldDeclType(QualType &Type, std::string &Result);
@@ -387,23 +391,23 @@
std::string &Result);
void RewriteObjCProtocolMetaData(ObjCProtocolDecl *Protocol,
std::string &Result);
- virtual void RewriteObjCProtocolListMetaData(
+ void RewriteObjCProtocolListMetaData(
const ObjCList<ObjCProtocolDecl> &Prots,
StringRef prefix, StringRef ClassName, std::string &Result);
- virtual void RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
+ void RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
std::string &Result);
- virtual void RewriteClassSetupInitHook(std::string &Result);
+ void RewriteClassSetupInitHook(std::string &Result);
- virtual void RewriteMetaDataIntoBuffer(std::string &Result);
- virtual void WriteImageInfo(std::string &Result);
- virtual void RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *CDecl,
+ void RewriteMetaDataIntoBuffer(std::string &Result);
+ void WriteImageInfo(std::string &Result);
+ void RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *CDecl,
std::string &Result);
- virtual void RewriteCategorySetupInitHook(std::string &Result);
+ void RewriteCategorySetupInitHook(std::string &Result);
// Rewriting ivar
- virtual void RewriteIvarOffsetComputation(ObjCIvarDecl *ivar,
+ void RewriteIvarOffsetComputation(ObjCIvarDecl *ivar,
std::string &Result);
- virtual Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV);
+ Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV);
std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag);
@@ -777,19 +781,34 @@
return S;
}
+/// mustSynthesizeSetterGetterMethod - returns true if setter or getter has not
+/// been found in the class implementation. In this case, it must be synthesized.
+static bool mustSynthesizeSetterGetterMethod(ObjCImplementationDecl *IMP,
+ ObjCPropertyDecl *PD,
+ bool getter) {
+ return getter ? !IMP->getInstanceMethod(PD->getGetterName())
+ : !IMP->getInstanceMethod(PD->getSetterName());
+
+}
+
void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID,
ObjCImplementationDecl *IMD,
ObjCCategoryImplDecl *CID) {
static bool objcGetPropertyDefined = false;
static bool objcSetPropertyDefined = false;
- SourceLocation startLoc = PID->getLocStart();
- InsertText(startLoc, "// ");
- const char *startBuf = SM->getCharacterData(startLoc);
- assert((*startBuf == '@') && "bogus @synthesize location");
- const char *semiBuf = strchr(startBuf, ';');
- assert((*semiBuf == ';') && "@synthesize: can't find ';'");
- SourceLocation onePastSemiLoc =
- startLoc.getLocWithOffset(semiBuf-startBuf+1);
+ SourceLocation startGetterSetterLoc;
+
+ if (PID->getLocStart().isValid()) {
+ SourceLocation startLoc = PID->getLocStart();
+ InsertText(startLoc, "// ");
+ const char *startBuf = SM->getCharacterData(startLoc);
+ assert((*startBuf == '@') && "bogus @synthesize location");
+ const char *semiBuf = strchr(startBuf, ';');
+ assert((*semiBuf == ';') && "@synthesize: can't find ';'");
+ startGetterSetterLoc = startLoc.getLocWithOffset(semiBuf-startBuf+1);
+ }
+ else
+ startGetterSetterLoc = IMD ? IMD->getLocEnd() : CID->getLocEnd();
if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
return; // FIXME: is this correct?
@@ -801,7 +820,7 @@
if (!OID)
return;
unsigned Attributes = PD->getPropertyAttributes();
- if (!PD->getGetterMethodDecl()->isDefined()) {
+ if (mustSynthesizeSetterGetterMethod(IMD, PD, true /*getter*/)) {
bool GenGetProperty = !(Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) &&
(Attributes & (ObjCPropertyDecl::OBJC_PR_retain |
ObjCPropertyDecl::OBJC_PR_copy));
@@ -853,10 +872,11 @@
else
Getr += "return " + getIvarAccessString(OID);
Getr += "; }";
- InsertText(onePastSemiLoc, Getr);
+ InsertText(startGetterSetterLoc, Getr);
}
- if (PD->isReadOnly() || PD->getSetterMethodDecl()->isDefined())
+ if (PD->isReadOnly() ||
+ !mustSynthesizeSetterGetterMethod(IMD, PD, false /*setter*/))
return;
// Generate the 'setter' function.
@@ -894,8 +914,8 @@
Setr += getIvarAccessString(OID) + " = ";
Setr += PD->getName();
}
- Setr += "; }";
- InsertText(onePastSemiLoc, Setr);
+ Setr += "; }\n";
+ InsertText(startGetterSetterLoc, Setr);
}
static void RewriteOneForwardClassDecl(ObjCInterfaceDecl *ForwardDecl,
@@ -984,21 +1004,17 @@
SourceLocation LocStart = CatDecl->getLocStart();
// FIXME: handle category headers that are declared across multiple lines.
- ReplaceText(LocStart, 0, "// ");
- if (CatDecl->getIvarLBraceLoc().isValid())
- InsertText(CatDecl->getIvarLBraceLoc(), "// ");
- for (ObjCCategoryDecl::ivar_iterator
- I = CatDecl->ivar_begin(), E = CatDecl->ivar_end(); I != E; ++I) {
- ObjCIvarDecl *Ivar = (*I);
- SourceLocation LocStart = Ivar->getLocStart();
+ if (CatDecl->getIvarRBraceLoc().isValid()) {
+ ReplaceText(LocStart, 1, "/** ");
+ ReplaceText(CatDecl->getIvarRBraceLoc(), 1, "**/ ");
+ }
+ else {
ReplaceText(LocStart, 0, "// ");
- }
- if (CatDecl->getIvarRBraceLoc().isValid())
- InsertText(CatDecl->getIvarRBraceLoc(), "// ");
+ }
for (ObjCCategoryDecl::prop_iterator I = CatDecl->prop_begin(),
E = CatDecl->prop_end(); I != E; ++I)
- RewriteProperty(*I);
+ RewriteProperty(&*I);
for (ObjCCategoryDecl::instmeth_iterator
I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end();
@@ -1032,7 +1048,7 @@
for (ObjCInterfaceDecl::prop_iterator I = PDecl->prop_begin(),
E = PDecl->prop_end(); I != E; ++I)
- RewriteProperty(*I);
+ RewriteProperty(&*I);
// Lastly, comment out the @end.
SourceLocation LocEnd = PDecl->getAtEndRange().getBegin();
@@ -1220,17 +1236,13 @@
ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID);
if (IMD) {
- InsertText(IMD->getLocStart(), "// ");
- if (IMD->getIvarLBraceLoc().isValid())
- InsertText(IMD->getIvarLBraceLoc(), "// ");
- for (ObjCImplementationDecl::ivar_iterator
- I = IMD->ivar_begin(), E = IMD->ivar_end(); I != E; ++I) {
- ObjCIvarDecl *Ivar = (*I);
- SourceLocation LocStart = Ivar->getLocStart();
- ReplaceText(LocStart, 0, "// ");
+ if (IMD->getIvarRBraceLoc().isValid()) {
+ ReplaceText(IMD->getLocStart(), 1, "/** ");
+ ReplaceText(IMD->getIvarRBraceLoc(), 1, "**/ ");
+ }
+ else {
+ InsertText(IMD->getLocStart(), "// ");
}
- if (IMD->getIvarRBraceLoc().isValid())
- InsertText(IMD->getIvarRBraceLoc(), "// ");
}
else
InsertText(CID->getLocStart(), "// ");
@@ -1268,7 +1280,7 @@
I = IMD ? IMD->propimpl_begin() : CID->propimpl_begin(),
E = IMD ? IMD->propimpl_end() : CID->propimpl_end();
I != E; ++I) {
- RewritePropertyImplDecl(*I, IMD, CID);
+ RewritePropertyImplDecl(&*I, IMD, CID);
}
InsertText(IMD ? IMD->getLocEnd() : CID->getLocEnd(), "// ");
@@ -1296,7 +1308,7 @@
for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(),
E = ClassDecl->prop_end(); I != E; ++I)
- RewriteProperty(*I);
+ RewriteProperty(&*I);
for (ObjCInterfaceDecl::instmeth_iterator
I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end();
I != E; ++I)
@@ -3494,10 +3506,44 @@
return false;
}
+/// IsTagDefinedInsideClass - This routine checks that a named tagged type
+/// is defined inside an objective-c class. If so, it returns true.
+bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCContainerDecl *IDecl,
+ TagDecl *Tag,
+ bool &IsNamedDefinition) {
+ if (!IDecl)
+ return false;
+ SourceLocation TagLocation;
+ if (RecordDecl *RD = dyn_cast<RecordDecl>(Tag)) {
+ RD = RD->getDefinition();
+ if (!RD || !RD->getDeclName().getAsIdentifierInfo())
+ return false;
+ IsNamedDefinition = true;
+ TagLocation = RD->getLocation();
+ return Context->getSourceManager().isBeforeInTranslationUnit(
+ IDecl->getLocation(), TagLocation);
+ }
+ if (EnumDecl *ED = dyn_cast<EnumDecl>(Tag)) {
+ if (!ED || !ED->getDeclName().getAsIdentifierInfo())
+ return false;
+ IsNamedDefinition = true;
+ TagLocation = ED->getLocation();
+ return Context->getSourceManager().isBeforeInTranslationUnit(
+ IDecl->getLocation(), TagLocation);
+
+ }
+ return false;
+}
+
/// RewriteObjCFieldDeclType - This routine rewrites a type into the buffer.
/// It handles elaborated types, as well as enum types in the process.
bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type,
std::string &Result) {
+ if (isa<TypedefType>(Type)) {
+ Result += "\t";
+ return false;
+ }
+
if (Type->isArrayType()) {
QualType ElemTy = Context->getBaseElementType(Type);
return RewriteObjCFieldDeclType(ElemTy, Result);
@@ -3513,16 +3559,15 @@
assert(false && "class not allowed as an ivar type");
Result += RD->getName();
- if (TagsDefinedInIvarDecls.count(RD)) {
- // This struct is already defined. Do not write its definition again.
+ if (GlobalDefinedTags.count(RD)) {
+ // struct/union is defined globally, use it.
Result += " ";
return true;
}
- TagsDefinedInIvarDecls.insert(RD);
Result += " {\n";
for (RecordDecl::field_iterator i = RD->field_begin(),
e = RD->field_end(); i != e; ++i) {
- FieldDecl *FD = *i;
+ FieldDecl *FD = &*i;
RewriteObjCFieldDecl(FD, Result);
}
Result += "\t} ";
@@ -3534,12 +3579,11 @@
if (ED->isCompleteDefinition()) {
Result += "\n\tenum ";
Result += ED->getName();
- if (TagsDefinedInIvarDecls.count(ED)) {
- // This enum is already defined. Do not write its definition again.
+ if (GlobalDefinedTags.count(ED)) {
+ // Enum is globall defined, use it.
Result += " ";
return true;
}
- TagsDefinedInIvarDecls.insert(ED);
Result += " {\n";
for (EnumDecl::enumerator_iterator EC = ED->enumerator_begin(),
@@ -3590,6 +3634,41 @@
Result += ";\n";
}
+/// RewriteLocallyDefinedNamedAggregates - This routine rewrites locally defined
+/// named aggregate types into the input buffer.
+void RewriteModernObjC::RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl,
+ std::string &Result) {
+ QualType Type = fieldDecl->getType();
+ if (isa<TypedefType>(Type))
+ return;
+ if (Type->isArrayType())
+ Type = Context->getBaseElementType(Type);
+ ObjCContainerDecl *IDecl =
+ dyn_cast<ObjCContainerDecl>(fieldDecl->getDeclContext());
+
+ TagDecl *TD = 0;
+ if (Type->isRecordType()) {
+ TD = Type->getAs<RecordType>()->getDecl();
+ }
+ else if (Type->isEnumeralType()) {
+ TD = Type->getAs<EnumType>()->getDecl();
+ }
+
+ if (TD) {
+ if (GlobalDefinedTags.count(TD))
+ return;
+
+ bool IsNamedDefinition = false;
+ if (IsTagDefinedInsideClass(IDecl, TD, IsNamedDefinition)) {
+ RewriteObjCFieldDeclType(Type, Result);
+ Result += ";";
+ }
+ if (IsNamedDefinition)
+ GlobalDefinedTags.insert(TD);
+ }
+
+}
+
/// RewriteObjCInternalStruct - Rewrite one internal struct corresponding to
/// an objective-c class with ivars.
void RewriteModernObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl,
@@ -3618,6 +3697,12 @@
return;
}
+ // Insert named struct/union definitions inside class to
+ // outer scope. This follows semantics of locally defined
+ // struct/unions in objective-c classes.
+ for (unsigned i = 0, e = IVars.size(); i < e; i++)
+ RewriteLocallyDefinedNamedAggregates(IVars[i], Result);
+
Result += "\nstruct ";
Result += CDecl->getNameAsString();
Result += "_IMPL {\n";
@@ -3627,7 +3712,7 @@
Result += "_IMPL "; Result += RCDecl->getNameAsString();
Result += "_IVARS;\n";
}
- TagsDefinedInIvarDecls.clear();
+
for (unsigned i = 0, e = IVars.size(); i < e; i++)
RewriteObjCFieldDecl(IVars[i], Result);
@@ -3984,8 +4069,8 @@
unsigned hasCopy) {
std::string S = "\nstatic struct " + DescTag;
- S += " {\n unsigned long reserved;\n";
- S += " unsigned long Block_size;\n";
+ S += " {\n size_t reserved;\n";
+ S += " size_t Block_size;\n";
if (hasCopy) {
S += " void (*copy)(struct ";
S += ImplTag; S += "*, struct ";
@@ -4814,8 +4899,13 @@
bool hasInit = (ND->getInit() != 0);
// FIXME. rewriter does not support __block c++ objects which
// require construction.
- if (hasInit && dyn_cast<CXXConstructExpr>(ND->getInit()))
- hasInit = false;
+ if (hasInit)
+ if (CXXConstructExpr *CExp = dyn_cast<CXXConstructExpr>(ND->getInit())) {
+ CXXConstructorDecl *CXXDecl = CExp->getConstructor();
+ if (CXXDecl && CXXDecl->isDefaultConstructor())
+ hasInit = false;
+ }
+
unsigned flags = 0;
if (HasCopyAndDispose)
flags |= BLOCK_HAS_COPY_DISPOSE;
@@ -5393,7 +5483,7 @@
void RewriteModernObjC::RewriteRecordBody(RecordDecl *RD) {
for (RecordDecl::field_iterator i = RD->field_begin(),
e = RD->field_end(); i != e; ++i) {
- FieldDecl *FD = *i;
+ FieldDecl *FD = &*i;
if (isTopLevelBlockPointerType(FD->getType()))
RewriteBlockPointerDecl(FD);
if (FD->getType()->isObjCQualifiedIdType() ||
@@ -5533,7 +5623,7 @@
std::string &Result) {
// Also output .objc_protorefs$B section and its meta-data.
if (Context->getLangOpts().MicrosoftExt)
- Result += "__declspec(allocate(\".objc_protorefs$B\")) ";
+ Result += "static ";
Result += "struct _protocol_t *";
Result += "_OBJC_PROTOCOL_REFERENCE_$_";
Result += PDecl->getNameAsString();
@@ -5623,7 +5713,6 @@
Preamble += "#pragma section(\".objc_imageinfo$B\", long, read, write)\n";
Preamble += "#pragma section(\".objc_nlclslist$B\", long, read, write)\n";
Preamble += "#pragma section(\".objc_nlcatlist$B\", long, read, write)\n";
- Preamble += "#pragma section(\".objc_protorefs$B\", long, read, write)\n";
// These are generated but not necessary for functionality.
Preamble += "#pragma section(\".cat_cls_meth$B\", long, read, write)\n";
Preamble += "#pragma section(\".inst_meth$B\", long, read, write)\n";
@@ -5741,7 +5830,7 @@
Preamble += "\t arr[i] = va_arg(marker, void *);\n";
Preamble += "\tva_end( marker );\n";
Preamble += " };\n";
- Preamble += " __NSContainer_literal() {\n";
+ Preamble += " ~__NSContainer_literal() {\n";
Preamble += "\tdelete[] arr;\n";
Preamble += " }\n";
Preamble += "};\n";
@@ -6585,7 +6674,7 @@
std::vector<ObjCPropertyDecl *> ProtocolProperties;
for (ObjCContainerDecl::prop_iterator I = PDecl->prop_begin(),
E = PDecl->prop_end(); I != E; ++I)
- ProtocolProperties.push_back(*I);
+ ProtocolProperties.push_back(&*I);
Write_prop_list_t_initializer(*this, Context, Result, ProtocolProperties,
/* Container */0,
@@ -6756,20 +6845,20 @@
for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(),
PropEnd = IDecl->propimpl_end();
Prop != PropEnd; ++Prop) {
- if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
+ if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
continue;
- if (!(*Prop)->getPropertyIvarDecl())
+ if (!Prop->getPropertyIvarDecl())
continue;
- ObjCPropertyDecl *PD = (*Prop)->getPropertyDecl();
+ ObjCPropertyDecl *PD = Prop->getPropertyDecl();
if (!PD)
continue;
if (ObjCMethodDecl *Getter = PD->getGetterMethodDecl())
- if (!Getter->isDefined())
+ if (mustSynthesizeSetterGetterMethod(IDecl, PD, true /*getter*/))
InstanceMethods.push_back(Getter);
if (PD->isReadOnly())
continue;
if (ObjCMethodDecl *Setter = PD->getSetterMethodDecl())
- if (!Setter->isDefined())
+ if (mustSynthesizeSetterGetterMethod(IDecl, PD, false /*setter*/))
InstanceMethods.push_back(Setter);
}
@@ -6806,7 +6895,7 @@
std::vector<ObjCPropertyDecl *> ClassProperties;
for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
E = CDecl->prop_end(); I != E; ++I)
- ClassProperties.push_back(*I);
+ ClassProperties.push_back(&*I);
Write_prop_list_t_initializer(*this, Context, Result, ClassProperties,
/* Container */IDecl,
@@ -7020,11 +7109,11 @@
for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(),
PropEnd = IDecl->propimpl_end();
Prop != PropEnd; ++Prop) {
- if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
+ if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
continue;
- if (!(*Prop)->getPropertyIvarDecl())
+ if (!Prop->getPropertyIvarDecl())
continue;
- ObjCPropertyDecl *PD = (*Prop)->getPropertyDecl();
+ ObjCPropertyDecl *PD = Prop->getPropertyDecl();
if (!PD)
continue;
if (ObjCMethodDecl *Getter = PD->getGetterMethodDecl())
@@ -7068,10 +7157,10 @@
std::vector<ObjCPropertyDecl *> ClassProperties;
for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
E = CDecl->prop_end(); I != E; ++I)
- ClassProperties.push_back(*I);
+ ClassProperties.push_back(&*I);
Write_prop_list_t_initializer(*this, Context, Result, ClassProperties,
- /* Container */0,
+ /* Container */IDecl,
"_OBJC_$_PROP_LIST_",
FullCategoryName);
@@ -7241,13 +7330,52 @@
SourceLocation(),
addExpr);
QualType IvarT = D->getType();
+
+ if (!isa<TypedefType>(IvarT) && IvarT->isRecordType()) {
+ RecordDecl *RD = IvarT->getAs<RecordType>()->getDecl();
+ RD = RD->getDefinition();
+ if (RD && !RD->getDeclName().getAsIdentifierInfo()) {
+ // decltype(((Foo_IMPL*)0)->bar) *
+ ObjCContainerDecl *CDecl =
+ dyn_cast<ObjCContainerDecl>(D->getDeclContext());
+ // ivar in class extensions requires special treatment.
+ if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
+ CDecl = CatDecl->getClassInterface();
+ std::string RecName = CDecl->getName();
+ RecName += "_IMPL";
+ RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
+ SourceLocation(), SourceLocation(),
+ &Context->Idents.get(RecName.c_str()));
+ QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD));
+ unsigned UnsignedIntSize =
+ static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy));
+ Expr *Zero = IntegerLiteral::Create(*Context,
+ llvm::APInt(UnsignedIntSize, 0),
+ Context->UnsignedIntTy, SourceLocation());
+ Zero = NoTypeInfoCStyleCastExpr(Context, PtrStructIMPL, CK_BitCast, Zero);
+ ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(),
+ Zero);
+ FieldDecl *FD = FieldDecl::Create(*Context, 0, SourceLocation(),
+ SourceLocation(),
+ &Context->Idents.get(D->getNameAsString()),
+ IvarT, 0,
+ /*BitWidth=*/0, /*Mutable=*/true,
+ /*HasInit=*/false);
+ MemberExpr *ME = new (Context) MemberExpr(PE, true, FD, SourceLocation(),
+ FD->getType(), VK_LValue,
+ OK_Ordinary);
+ IvarT = Context->getDecltypeType(ME, ME->getType());
+ }
+ }
convertObjCTypeToCStyleType(IvarT);
QualType castT = Context->getPointerType(IvarT);
-
+
castExpr = NoTypeInfoCStyleCastExpr(Context,
castT,
CK_BitCast,
PE);
+
+
Expr *Exp = new (Context) UnaryOperator(castExpr, UO_Deref, IvarT,
VK_LValue, OK_Ordinary,
SourceLocation());
Modified: cfe/branches/tooling/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Rewrite/RewriteObjC.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/branches/tooling/lib/Rewrite/RewriteObjC.cpp Tue May 8 03:47:31 2012
@@ -967,7 +967,7 @@
for (ObjCCategoryDecl::prop_iterator I = CatDecl->prop_begin(),
E = CatDecl->prop_end(); I != E; ++I)
- RewriteProperty(*I);
+ RewriteProperty(&*I);
for (ObjCCategoryDecl::instmeth_iterator
I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end();
@@ -1001,7 +1001,7 @@
for (ObjCInterfaceDecl::prop_iterator I = PDecl->prop_begin(),
E = PDecl->prop_end(); I != E; ++I)
- RewriteProperty(*I);
+ RewriteProperty(&*I);
// Lastly, comment out the @end.
SourceLocation LocEnd = PDecl->getAtEndRange().getBegin();
@@ -1207,7 +1207,7 @@
I = IMD ? IMD->propimpl_begin() : CID->propimpl_begin(),
E = IMD ? IMD->propimpl_end() : CID->propimpl_end();
I != E; ++I) {
- RewritePropertyImplDecl(*I, IMD, CID);
+ RewritePropertyImplDecl(&*I, IMD, CID);
}
InsertText(IMD ? IMD->getLocEnd() : CID->getLocEnd(), "// ");
@@ -1233,7 +1233,7 @@
for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(),
E = ClassDecl->prop_end(); I != E; ++I)
- RewriteProperty(*I);
+ RewriteProperty(&*I);
for (ObjCInterfaceDecl::instmeth_iterator
I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end();
I != E; ++I)
@@ -4881,7 +4881,7 @@
void RewriteObjC::RewriteRecordBody(RecordDecl *RD) {
for (RecordDecl::field_iterator i = RD->field_begin(),
e = RD->field_end(); i != e; ++i) {
- FieldDecl *FD = *i;
+ FieldDecl *FD = &*i;
if (isTopLevelBlockPointerType(FD->getType()))
RewriteBlockPointerDecl(FD);
if (FD->getType()->isObjCQualifiedIdType() ||
@@ -5434,7 +5434,7 @@
for (ObjCInterfaceDecl::ivar_iterator
IV = IDecl->ivar_begin(), IVEnd = IDecl->ivar_end();
IV != IVEnd; ++IV)
- IVars.push_back(*IV);
+ IVars.push_back(&*IV);
IVI = IDecl->ivar_begin();
IVE = IDecl->ivar_end();
} else {
@@ -5442,25 +5442,25 @@
IVE = CDecl->ivar_end();
}
Result += "\t,{{\"";
- Result += (*IVI)->getNameAsString();
+ Result += IVI->getNameAsString();
Result += "\", \"";
std::string TmpString, StrEncoding;
- Context->getObjCEncodingForType((*IVI)->getType(), TmpString, *IVI);
+ Context->getObjCEncodingForType(IVI->getType(), TmpString, &*IVI);
QuoteDoublequotes(TmpString, StrEncoding);
Result += StrEncoding;
Result += "\", ";
- RewriteIvarOffsetComputation(*IVI, Result);
+ RewriteIvarOffsetComputation(&*IVI, Result);
Result += "}\n";
for (++IVI; IVI != IVE; ++IVI) {
Result += "\t ,{\"";
- Result += (*IVI)->getNameAsString();
+ Result += IVI->getNameAsString();
Result += "\", \"";
std::string TmpString, StrEncoding;
- Context->getObjCEncodingForType((*IVI)->getType(), TmpString, *IVI);
+ Context->getObjCEncodingForType(IVI->getType(), TmpString, &*IVI);
QuoteDoublequotes(TmpString, StrEncoding);
Result += StrEncoding;
Result += "\", ";
- RewriteIvarOffsetComputation((*IVI), Result);
+ RewriteIvarOffsetComputation(&*IVI, Result);
Result += "}\n";
}
@@ -5476,11 +5476,11 @@
for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(),
PropEnd = IDecl->propimpl_end();
Prop != PropEnd; ++Prop) {
- if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
+ if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
continue;
- if (!(*Prop)->getPropertyIvarDecl())
+ if (!Prop->getPropertyIvarDecl())
continue;
- ObjCPropertyDecl *PD = (*Prop)->getPropertyDecl();
+ ObjCPropertyDecl *PD = Prop->getPropertyDecl();
if (!PD)
continue;
if (ObjCMethodDecl *Getter = PD->getGetterMethodDecl())
@@ -5761,11 +5761,11 @@
for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(),
PropEnd = IDecl->propimpl_end();
Prop != PropEnd; ++Prop) {
- if ((*Prop)->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
+ if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
continue;
- if (!(*Prop)->getPropertyIvarDecl())
+ if (!Prop->getPropertyIvarDecl())
continue;
- ObjCPropertyDecl *PD = (*Prop)->getPropertyDecl();
+ ObjCPropertyDecl *PD = Prop->getPropertyDecl();
if (!PD)
continue;
if (ObjCMethodDecl *Getter = PD->getGetterMethodDecl())
Modified: cfe/branches/tooling/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/AnalysisBasedWarnings.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/branches/tooling/lib/Sema/AnalysisBasedWarnings.cpp Tue May 8 03:47:31 2012
@@ -27,6 +27,7 @@
#include "clang/AST/StmtCXX.h"
#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/AST/StmtVisitor.h"
+#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Analysis/AnalysisContext.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/Analyses/ReachableCode.h"
@@ -42,7 +43,9 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include <algorithm>
+#include <iterator>
#include <vector>
+#include <deque>
using namespace clang;
@@ -438,9 +441,14 @@
return false;
// Suggest possible initialization (if any).
- const char *Init = S.getFixItZeroInitializerForType(VariableTy);
- if (!Init)
+ std::string Init = S.getFixItZeroInitializerForType(VariableTy);
+ if (Init.empty())
return false;
+
+ // Don't suggest a fixit inside macros.
+ if (VD->getLocEnd().isMacroID())
+ return false;
+
SourceLocation Loc = S.PP.getLocForEndOfToken(VD->getLocEnd());
S.Diag(Loc, diag::note_var_fixit_add_initialization) << VD->getDeclName()
@@ -517,6 +525,189 @@
return true;
}
+namespace {
+ class FallthroughMapper : public RecursiveASTVisitor<FallthroughMapper> {
+ public:
+ FallthroughMapper(Sema &S)
+ : FoundSwitchStatements(false),
+ S(S) {
+ }
+
+ bool foundSwitchStatements() const { return FoundSwitchStatements; }
+
+ void markFallthroughVisited(const AttributedStmt *Stmt) {
+ bool Found = FallthroughStmts.erase(Stmt);
+ assert(Found);
+ (void)Found;
+ }
+
+ typedef llvm::SmallPtrSet<const AttributedStmt*, 8> AttrStmts;
+
+ const AttrStmts &getFallthroughStmts() const {
+ return FallthroughStmts;
+ }
+
+ bool checkFallThroughIntoBlock(const CFGBlock &B, int &AnnotatedCnt) {
+ int UnannotatedCnt = 0;
+ AnnotatedCnt = 0;
+
+ std::deque<const CFGBlock*> BlockQueue;
+
+ std::copy(B.pred_begin(), B.pred_end(), std::back_inserter(BlockQueue));
+
+ while (!BlockQueue.empty()) {
+ const CFGBlock *P = BlockQueue.front();
+ BlockQueue.pop_front();
+
+ const Stmt *Term = P->getTerminator();
+ if (Term && isa<SwitchStmt>(Term))
+ continue; // Switch statement, good.
+
+ const SwitchCase *SW = dyn_cast_or_null<SwitchCase>(P->getLabel());
+ if (SW && SW->getSubStmt() == B.getLabel() && P->begin() == P->end())
+ continue; // Previous case label has no statements, good.
+
+ if (P->pred_begin() == P->pred_end()) { // The block is unreachable.
+ // This only catches trivially unreachable blocks.
+ for (CFGBlock::const_iterator ElIt = P->begin(), ElEnd = P->end();
+ ElIt != ElEnd; ++ElIt) {
+ if (const CFGStmt *CS = ElIt->getAs<CFGStmt>()){
+ if (const AttributedStmt *AS = asFallThroughAttr(CS->getStmt())) {
+ S.Diag(AS->getLocStart(),
+ diag::warn_fallthrough_attr_unreachable);
+ markFallthroughVisited(AS);
+ ++AnnotatedCnt;
+ }
+ // Don't care about other unreachable statements.
+ }
+ }
+ // If there are no unreachable statements, this may be a special
+ // case in CFG:
+ // case X: {
+ // A a; // A has a destructor.
+ // break;
+ // }
+ // // <<<< This place is represented by a 'hanging' CFG block.
+ // case Y:
+ continue;
+ }
+
+ const Stmt *LastStmt = getLastStmt(*P);
+ if (const AttributedStmt *AS = asFallThroughAttr(LastStmt)) {
+ markFallthroughVisited(AS);
+ ++AnnotatedCnt;
+ continue; // Fallthrough annotation, good.
+ }
+
+ if (!LastStmt) { // This block contains no executable statements.
+ // Traverse its predecessors.
+ std::copy(P->pred_begin(), P->pred_end(),
+ std::back_inserter(BlockQueue));
+ continue;
+ }
+
+ ++UnannotatedCnt;
+ }
+ return !!UnannotatedCnt;
+ }
+
+ // RecursiveASTVisitor setup.
+ bool shouldWalkTypesOfTypeLocs() const { return false; }
+
+ bool VisitAttributedStmt(AttributedStmt *S) {
+ if (asFallThroughAttr(S))
+ FallthroughStmts.insert(S);
+ return true;
+ }
+
+ bool VisitSwitchStmt(SwitchStmt *S) {
+ FoundSwitchStatements = true;
+ return true;
+ }
+
+ private:
+
+ static const AttributedStmt *asFallThroughAttr(const Stmt *S) {
+ if (const AttributedStmt *AS = dyn_cast_or_null<AttributedStmt>(S)) {
+ if (hasSpecificAttr<FallThroughAttr>(AS->getAttrs()))
+ return AS;
+ }
+ return 0;
+ }
+
+ static const Stmt *getLastStmt(const CFGBlock &B) {
+ if (const Stmt *Term = B.getTerminator())
+ return Term;
+ for (CFGBlock::const_reverse_iterator ElemIt = B.rbegin(),
+ ElemEnd = B.rend();
+ ElemIt != ElemEnd; ++ElemIt) {
+ if (const CFGStmt *CS = ElemIt->getAs<CFGStmt>())
+ return CS->getStmt();
+ }
+ // Workaround to detect a statement thrown out by CFGBuilder:
+ // case X: {} case Y:
+ // case X: ; case Y:
+ if (const SwitchCase *SW = dyn_cast_or_null<SwitchCase>(B.getLabel()))
+ if (!isa<SwitchCase>(SW->getSubStmt()))
+ return SW->getSubStmt();
+
+ return 0;
+ }
+
+ bool FoundSwitchStatements;
+ AttrStmts FallthroughStmts;
+ Sema &S;
+ };
+}
+
+static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC) {
+ FallthroughMapper FM(S);
+ FM.TraverseStmt(AC.getBody());
+
+ if (!FM.foundSwitchStatements())
+ return;
+
+ CFG *Cfg = AC.getCFG();
+
+ if (!Cfg)
+ return;
+
+ int AnnotatedCnt;
+
+ for (CFG::reverse_iterator I = Cfg->rbegin(), E = Cfg->rend(); I != E; ++I) {
+ const CFGBlock &B = **I;
+ const Stmt *Label = B.getLabel();
+
+ if (!Label || !isa<SwitchCase>(Label))
+ continue;
+
+ if (!FM.checkFallThroughIntoBlock(B, AnnotatedCnt))
+ continue;
+
+ S.Diag(Label->getLocStart(), diag::warn_unannotated_fallthrough);
+
+ if (!AnnotatedCnt) {
+ SourceLocation L = Label->getLocStart();
+ if (L.isMacroID())
+ continue;
+ if (S.getLangOpts().CPlusPlus0x) {
+ S.Diag(L, diag::note_insert_fallthrough_fixit) <<
+ FixItHint::CreateInsertion(L, "[[clang::fallthrough]]; ");
+ }
+ S.Diag(L, diag::note_insert_break_fixit) <<
+ FixItHint::CreateInsertion(L, "break; ");
+ }
+ }
+
+ const FallthroughMapper::AttrStmts &Fallthroughs = FM.getFallthroughStmts();
+ for (FallthroughMapper::AttrStmts::const_iterator I = Fallthroughs.begin(),
+ E = Fallthroughs.end();
+ I != E; ++I) {
+ S.Diag((*I)->getLocStart(), diag::warn_fallthrough_attr_invalid_placement);
+ }
+
+}
+
typedef std::pair<const Expr*, bool> UninitUse;
namespace {
@@ -830,7 +1021,7 @@
const Stmt *Body = D->getBody();
assert(Body);
- AnalysisDeclContext AC(/* AnalysisDeclContextManager */ 0, D, 0);
+ AnalysisDeclContext AC(/* AnalysisDeclContextManager */ 0, D);
// Don't generate EH edges for CallExprs as we'd like to avoid the n^2
// explosion for destrutors that can result and the compile time hit.
@@ -856,7 +1047,8 @@
.setAlwaysAdd(Stmt::CStyleCastExprClass)
.setAlwaysAdd(Stmt::DeclRefExprClass)
.setAlwaysAdd(Stmt::ImplicitCastExprClass)
- .setAlwaysAdd(Stmt::UnaryOperatorClass);
+ .setAlwaysAdd(Stmt::UnaryOperatorClass)
+ .setAlwaysAdd(Stmt::AttributedStmtClass);
}
// Construct the analysis context with the specified CFG build options.
@@ -968,6 +1160,11 @@
}
}
+ if (Diags.getDiagnosticLevel(diag::warn_unannotated_fallthrough,
+ D->getLocStart()) != DiagnosticsEngine::Ignored) {
+ DiagnoseSwitchLabelsFallthrough(S, AC);
+ }
+
// Collect statistics about the CFG if it was built.
if (S.CollectStats && AC.isCFGBuilt()) {
++NumFunctionsAnalyzed;
Modified: cfe/branches/tooling/lib/Sema/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/AttributeList.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/AttributeList.cpp (original)
+++ cfe/branches/tooling/lib/Sema/AttributeList.cpp Tue May 8 03:47:31 2012
@@ -15,6 +15,7 @@
#include "clang/AST/Expr.h"
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/SmallString.h"
using namespace clang;
size_t AttributeList::allocated_size() const {
@@ -97,7 +98,10 @@
return create(Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0);
}
-AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
+#include "clang/Sema/AttrParsedAttrKinds.inc"
+
+AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name,
+ const IdentifierInfo *ScopeName) {
StringRef AttrName = Name->getName();
// Normalize the attribute name, __foo__ becomes foo.
@@ -105,22 +109,10 @@
AttrName.size() >= 4)
AttrName = AttrName.substr(2, AttrName.size() - 4);
- return llvm::StringSwitch<AttributeList::Kind>(AttrName)
- #include "clang/Sema/AttrParsedAttrKinds.inc"
- .Case("address_space", AT_address_space)
- .Case("align", AT_aligned) // FIXME - should it be "aligned"?
- .Case("base_check", AT_base_check)
- .Case("bounded", IgnoredAttribute) // OpenBSD
- .Case("__const", AT_const) // some GCC headers do contain this spelling
- .Case("cf_returns_autoreleased", AT_cf_returns_autoreleased)
- .Case("mode", AT_mode)
- .Case("vec_type_hint", IgnoredAttribute)
- .Case("ext_vector_type", AT_ext_vector_type)
- .Case("neon_vector_type", AT_neon_vector_type)
- .Case("neon_polyvector_type", AT_neon_polyvector_type)
- .Case("opencl_image_access", AT_opencl_image_access)
- .Case("objc_gc", AT_objc_gc)
- .Case("objc_ownership", AT_objc_ownership)
- .Case("vector_size", AT_vector_size)
- .Default(UnknownAttribute);
+ // FIXME: implement attribute namespacing correctly.
+ SmallString<64> Buf;
+ if (ScopeName)
+ AttrName = ((Buf += ScopeName->getName()) += "___") += AttrName;
+
+ return ::getAttrKind(AttrName);
}
Modified: cfe/branches/tooling/lib/Sema/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/DeclSpec.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/DeclSpec.cpp (original)
+++ cfe/branches/tooling/lib/Sema/DeclSpec.cpp Tue May 8 03:47:31 2012
@@ -162,7 +162,6 @@
SourceRange *ExceptionRanges,
unsigned NumExceptions,
Expr *NoexceptExpr,
- CachedTokens *ExceptionSpecTokens,
SourceLocation LocalRangeBegin,
SourceLocation LocalRangeEnd,
Declarator &TheDeclarator,
@@ -227,10 +226,6 @@
case EST_ComputedNoexcept:
I.Fun.NoexceptExpr = NoexceptExpr;
break;
-
- case EST_Delayed:
- I.Fun.ExceptionSpecTokens = ExceptionSpecTokens;
- break;
}
return I;
}
Modified: cfe/branches/tooling/lib/Sema/IdentifierResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/IdentifierResolver.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/IdentifierResolver.cpp (original)
+++ cfe/branches/tooling/lib/Sema/IdentifierResolver.cpp Tue May 8 03:47:31 2012
@@ -304,7 +304,7 @@
for (Decl::redecl_iterator RD = New->redecls_begin(),
RDEnd = New->redecls_end();
RD != RDEnd; ++RD) {
- if (*RD == Existing)
+ if (RD == Existing)
return DMK_Replace;
if (RD->isCanonicalDecl())
Modified: cfe/branches/tooling/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/Sema.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/Sema.cpp (original)
+++ cfe/branches/tooling/lib/Sema/Sema.cpp Tue May 8 03:47:31 2012
@@ -18,6 +18,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/APFloat.h"
+#include "llvm/Support/CrashRecoveryContext.h"
#include "clang/Sema/CXXFieldCollector.h"
#include "clang/Sema/TemplateDeduction.h"
#include "clang/Sema/ExternalSemaSource.h"
@@ -98,7 +99,7 @@
ObjCShouldCallSuperDealloc(false),
ObjCShouldCallSuperFinalize(false),
TUKind(TUKind),
- NumSFINAEErrors(0), InFunctionDeclarator(0), SuppressAccessChecking(false),
+ NumSFINAEErrors(0), InFunctionDeclarator(0),
AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),
NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),
CurrentInstantiationScope(0), TyposCorrected(0),
@@ -201,7 +202,6 @@
ExternalSema->ForgetSema();
}
-
/// makeUnavailableInSystemHeader - There is an error in the current
/// context. If we're still in a system header, and we can plausibly
/// make the relevant declaration unavailable instead of erroring, do
@@ -426,6 +426,9 @@
/// translation unit when EOF is reached and all but the top-level scope is
/// popped.
void Sema::ActOnEndOfTranslationUnit() {
+ assert(DelayedDiagnostics.getCurrentPool() == NULL
+ && "reached end of translation unit with a pool attached?");
+
// Only complete translation units define vtables and perform implicit
// instantiations.
if (TUKind == TU_Complete) {
@@ -695,6 +698,15 @@
// Count this failure so that we know that template argument deduction
// has failed.
++NumSFINAEErrors;
+
+ // Make a copy of this suppressed diagnostic and store it with the
+ // template-deduction information.
+ if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
+ Diagnostic DiagInfo(&Diags);
+ (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
+ PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ }
+
Diags.setLastDiagnosticIgnored();
Diags.Clear();
return;
@@ -711,6 +723,15 @@
// Suppress this diagnostic.
++NumSFINAEErrors;
+
+ // Make a copy of this suppressed diagnostic and store it with the
+ // template-deduction information.
+ if (*Info && !(*Info)->hasSFINAEDiagnostic()) {
+ Diagnostic DiagInfo(&Diags);
+ (*Info)->addSFINAEDiagnostic(DiagInfo.getLocation(),
+ PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ }
+
Diags.setLastDiagnosticIgnored();
Diags.Clear();
@@ -727,13 +748,13 @@
case DiagnosticIDs::SFINAE_Suppress:
// Make a copy of this suppressed diagnostic and store it with the
// template-deduction information;
- Diagnostic DiagInfo(&Diags);
-
- if (*Info)
+ if (*Info) {
+ Diagnostic DiagInfo(&Diags);
(*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(),
- PartialDiagnostic(DiagInfo,Context.getDiagAllocator()));
-
- // Suppress this diagnostic.
+ PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ }
+
+ // Suppress this diagnostic.
Diags.setLastDiagnosticIgnored();
Diags.Clear();
return;
Modified: cfe/branches/tooling/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaAccess.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaAccess.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaAccess.cpp Tue May 8 03:47:31 2012
@@ -1391,9 +1391,6 @@
if (Entity.getAccess() == AS_public)
return Sema::AR_accessible;
- if (S.SuppressAccessChecking)
- return Sema::AR_accessible;
-
// If we're currently parsing a declaration, we may need to delay
// access control checking, because our effective context might be
// different based on what the declaration comes out as.
@@ -1836,15 +1833,3 @@
return true;
}
-
-void Sema::ActOnStartSuppressingAccessChecks() {
- assert(!SuppressAccessChecking &&
- "Tried to start access check suppression when already started.");
- SuppressAccessChecking = true;
-}
-
-void Sema::ActOnStopSuppressingAccessChecks() {
- assert(SuppressAccessChecking &&
- "Tried to stop access check suprression when already stopped.");
- SuppressAccessChecking = false;
-}
Modified: cfe/branches/tooling/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaCXXScopeSpec.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaCXXScopeSpec.cpp Tue May 8 03:47:31 2012
@@ -227,9 +227,8 @@
if (loc.isInvalid()) loc = SS.getRange().getBegin();
// The type must be complete.
- if (RequireCompleteType(loc, type,
- PDiag(diag::err_incomplete_nested_name_spec)
- << SS.getRange())) {
+ if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
+ SS.getRange())) {
SS.SetInvalid(SS.getRange());
return true;
}
@@ -539,8 +538,9 @@
NamedDecl *SD = Found.getAsSingle<NamedDecl>();
if (isAcceptableNestedNameSpecifier(SD)) {
- if (!ObjectType.isNull() && !ObjectTypeSearchedInScope) {
- // C++ [basic.lookup.classref]p4:
+ if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
+ !getLangOpts().CPlusPlus0x) {
+ // C++03 [basic.lookup.classref]p4:
// [...] If the name is found in both contexts, the
// class-name-or-namespace-name shall refer to the same entity.
//
@@ -548,6 +548,8 @@
// into the current scope (the scope of the postfix-expression) to
// see if we can find the same name there. As above, if there is no
// scope, reconstruct the result from the template instantiation itself.
+ //
+ // Note that C++11 does *not* perform this redundant lookup.
NamedDecl *OuterDecl;
if (S) {
LookupResult FoundOuter(*this, &Identifier, IdentifierLoc,
Modified: cfe/branches/tooling/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaCast.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaCast.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaCast.cpp Tue May 8 03:47:31 2012
@@ -561,8 +561,8 @@
assert(DestPointer && "Reference to void is not possible");
} else if (DestRecord) {
if (Self.RequireCompleteType(OpRange.getBegin(), DestPointee,
- Self.PDiag(diag::err_bad_dynamic_cast_incomplete)
- << DestRange))
+ diag::err_bad_dynamic_cast_incomplete,
+ DestRange))
return;
} else {
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
@@ -597,8 +597,8 @@
const RecordType *SrcRecord = SrcPointee->getAs<RecordType>();
if (SrcRecord) {
if (Self.RequireCompleteType(OpRange.getBegin(), SrcPointee,
- Self.PDiag(diag::err_bad_dynamic_cast_incomplete)
- << SrcExpr.get()->getSourceRange()))
+ diag::err_bad_dynamic_cast_incomplete,
+ SrcExpr.get()))
return;
} else {
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
@@ -1075,8 +1075,8 @@
QualType OrigDestType, unsigned &msg,
CastKind &Kind, CXXCastPath &BasePath) {
// We can only work with complete types. But don't complain if it doesn't work
- if (Self.RequireCompleteType(OpRange.getBegin(), SrcType, Self.PDiag(0)) ||
- Self.RequireCompleteType(OpRange.getBegin(), DestType, Self.PDiag(0)))
+ if (Self.RequireCompleteType(OpRange.getBegin(), SrcType, 0) ||
+ Self.RequireCompleteType(OpRange.getBegin(), DestType, 0))
return TC_NotApplicable;
// Downcast can only happen in class hierarchies, so we need classes.
@@ -1302,7 +1302,9 @@
CastKind &Kind, bool ListInitialization) {
if (DestType->isRecordType()) {
if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
- diag::err_bad_dynamic_cast_incomplete)) {
+ diag::err_bad_dynamic_cast_incomplete) ||
+ Self.RequireNonAbstractType(OpRange.getBegin(), DestType,
+ diag::err_allocation_of_abstract_type)) {
msg = 0;
return TC_Failed;
}
@@ -1504,10 +1506,9 @@
}
if (const ReferenceType *DestTypeTmp = DestType->getAs<ReferenceType>()) {
- bool LValue = DestTypeTmp->isLValueReferenceType();
- if (LValue && !SrcExpr.get()->isLValue()) {
- // Cannot cast non-lvalue to lvalue reference type. See the similar
- // comment in const_cast.
+ if (!SrcExpr.get()->isGLValue()) {
+ // Cannot cast non-glvalue to (lvalue or rvalue) reference type. See the
+ // similar comment in const_cast.
msg = diag::err_bad_cxx_cast_rvalue;
return TC_NotApplicable;
}
Modified: cfe/branches/tooling/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaChecking.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaChecking.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaChecking.cpp Tue May 8 03:47:31 2012
@@ -66,16 +66,31 @@
<< call->getArg(1)->getSourceRange();
}
-/// CheckBuiltinAnnotationString - Checks that string argument to the builtin
-/// annotation is a non wide string literal.
-static bool CheckBuiltinAnnotationString(Sema &S, Expr *Arg) {
- Arg = Arg->IgnoreParenCasts();
- StringLiteral *Literal = dyn_cast<StringLiteral>(Arg);
+/// Check that the first argument to __builtin_annotation is an integer
+/// and the second argument is a non-wide string literal.
+static bool SemaBuiltinAnnotation(Sema &S, CallExpr *TheCall) {
+ if (checkArgCount(S, TheCall, 2))
+ return true;
+
+ // First argument should be an integer.
+ Expr *ValArg = TheCall->getArg(0);
+ QualType Ty = ValArg->getType();
+ if (!Ty->isIntegerType()) {
+ S.Diag(ValArg->getLocStart(), diag::err_builtin_annotation_first_arg)
+ << ValArg->getSourceRange();
+ return true;
+ }
+
+ // Second argument should be a constant string.
+ Expr *StrArg = TheCall->getArg(1)->IgnoreParenCasts();
+ StringLiteral *Literal = dyn_cast<StringLiteral>(StrArg);
if (!Literal || !Literal->isAscii()) {
- S.Diag(Arg->getLocStart(), diag::err_builtin_annotation_not_string_constant)
- << Arg->getSourceRange();
+ S.Diag(StrArg->getLocStart(), diag::err_builtin_annotation_second_arg)
+ << StrArg->getSourceRange();
return true;
}
+
+ TheCall->setType(Ty);
return false;
}
@@ -256,7 +271,7 @@
return SemaAtomicOpsOverloaded(move(TheCallResult), AtomicExpr::AO##ID);
#include "clang/Basic/Builtins.def"
case Builtin::BI__builtin_annotation:
- if (CheckBuiltinAnnotationString(*this, TheCall->getArg(1)))
+ if (SemaBuiltinAnnotation(*this, TheCall))
return ExprError();
break;
}
@@ -1734,7 +1749,8 @@
// format is either NSString or CFString. This is a hack to prevent
// diag when using the NSLocalizedString and CFCopyLocalizedString macros
// which are usually used in place of NS and CF string literals.
- if (Type == FST_NSString && Args[format_idx]->getLocStart().isMacroID())
+ if (Type == FST_NSString &&
+ SourceMgr.isInSystemMacro(Args[format_idx]->getLocStart()))
return;
// If there are no arguments specified, warn with -Wformat-security, otherwise
@@ -1960,9 +1976,12 @@
signed notCoveredArg = CoveredArgs.find_first();
if (notCoveredArg >= 0) {
assert((unsigned)notCoveredArg < NumDataArgs);
- EmitFormatDiagnostic(S.PDiag(diag::warn_printf_data_arg_not_used),
- getDataArg((unsigned) notCoveredArg)->getLocStart(),
- /*IsStringLocation*/false, getFormatStringRange());
+ SourceLocation Loc = getDataArg((unsigned) notCoveredArg)->getLocStart();
+ if (!S.getSourceManager().isInSystemMacro(Loc)) {
+ EmitFormatDiagnostic(S.PDiag(diag::warn_printf_data_arg_not_used),
+ Loc,
+ /*IsStringLocation*/false, getFormatStringRange());
+ }
}
}
}
@@ -2374,7 +2393,8 @@
// or 'short' to an 'int'. This is done because printf is a varargs
// function.
if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Ex))
- if (ICE->getType() == S.Context.IntTy) {
+ if (ICE->getType() == S.Context.IntTy ||
+ ICE->getType() == S.Context.UnsignedIntTy) {
// All further checking is done on the subexpression.
Ex = ICE->getSubExpr();
if (ATR.matchesType(S.Context, Ex->getType()))
@@ -3002,8 +3022,10 @@
//===--- CHECK: Return Address of Stack Variable --------------------------===//
-static Expr *EvalVal(Expr *E, SmallVectorImpl<DeclRefExpr *> &refVars);
-static Expr *EvalAddr(Expr* E, SmallVectorImpl<DeclRefExpr *> &refVars);
+static Expr *EvalVal(Expr *E, SmallVectorImpl<DeclRefExpr *> &refVars,
+ Decl *ParentDecl);
+static Expr *EvalAddr(Expr* E, SmallVectorImpl<DeclRefExpr *> &refVars,
+ Decl *ParentDecl);
/// CheckReturnStackAddr - Check if a return statement returns the address
/// of a stack variable.
@@ -3018,9 +3040,9 @@
// label addresses or references to temporaries.
if (lhsType->isPointerType() ||
(!getLangOpts().ObjCAutoRefCount && lhsType->isBlockPointerType())) {
- stackE = EvalAddr(RetValExp, refVars);
+ stackE = EvalAddr(RetValExp, refVars, /*ParentDecl=*/0);
} else if (lhsType->isReferenceType()) {
- stackE = EvalVal(RetValExp, refVars);
+ stackE = EvalVal(RetValExp, refVars, /*ParentDecl=*/0);
}
if (stackE == 0)
@@ -3094,7 +3116,8 @@
/// * arbitrary interplay between "&" and "*" operators
/// * pointer arithmetic from an address of a stack variable
/// * taking the address of an array element where the array is on the stack
-static Expr *EvalAddr(Expr *E, SmallVectorImpl<DeclRefExpr *> &refVars) {
+static Expr *EvalAddr(Expr *E, SmallVectorImpl<DeclRefExpr *> &refVars,
+ Decl *ParentDecl) {
if (E->isTypeDependent())
return NULL;
@@ -3120,7 +3143,7 @@
V->getType()->isReferenceType() && V->hasInit()) {
// Add the reference variable to the "trail".
refVars.push_back(DR);
- return EvalAddr(V->getInit(), refVars);
+ return EvalAddr(V->getInit(), refVars, ParentDecl);
}
return NULL;
@@ -3132,7 +3155,7 @@
UnaryOperator *U = cast<UnaryOperator>(E);
if (U->getOpcode() == UO_AddrOf)
- return EvalVal(U->getSubExpr(), refVars);
+ return EvalVal(U->getSubExpr(), refVars, ParentDecl);
else
return NULL;
}
@@ -3153,7 +3176,7 @@
if (!Base->getType()->isPointerType()) Base = B->getRHS();
assert (Base->getType()->isPointerType());
- return EvalAddr(Base, refVars);
+ return EvalAddr(Base, refVars, ParentDecl);
}
// For conditional operators we need to see if either the LHS or RHS are
@@ -3165,7 +3188,7 @@
if (Expr *lhsExpr = C->getLHS()) {
// In C++, we can have a throw-expression, which has 'void' type.
if (!lhsExpr->getType()->isVoidType())
- if (Expr* LHS = EvalAddr(lhsExpr, refVars))
+ if (Expr* LHS = EvalAddr(lhsExpr, refVars, ParentDecl))
return LHS;
}
@@ -3173,7 +3196,7 @@
if (C->getRHS()->getType()->isVoidType())
return NULL;
- return EvalAddr(C->getRHS(), refVars);
+ return EvalAddr(C->getRHS(), refVars, ParentDecl);
}
case Stmt::BlockExprClass:
@@ -3185,7 +3208,8 @@
return E; // address of label.
case Stmt::ExprWithCleanupsClass:
- return EvalAddr(cast<ExprWithCleanups>(E)->getSubExpr(), refVars);
+ return EvalAddr(cast<ExprWithCleanups>(E)->getSubExpr(), refVars,
+ ParentDecl);
// For casts, we need to handle conversions from arrays to
// pointer values, and pointer-to-pointer conversions.
@@ -3209,10 +3233,10 @@
case CK_CPointerToObjCPointerCast:
case CK_BlockPointerToObjCPointerCast:
case CK_AnyPointerToBlockPointerCast:
- return EvalAddr(SubExpr, refVars);
+ return EvalAddr(SubExpr, refVars, ParentDecl);
case CK_ArrayToPointerDecay:
- return EvalVal(SubExpr, refVars);
+ return EvalVal(SubExpr, refVars, ParentDecl);
default:
return 0;
@@ -3222,7 +3246,7 @@
case Stmt::MaterializeTemporaryExprClass:
if (Expr *Result = EvalAddr(
cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr(),
- refVars))
+ refVars, ParentDecl))
return Result;
return E;
@@ -3236,7 +3260,8 @@
/// EvalVal - This function is complements EvalAddr in the mutual recursion.
/// See the comments for EvalAddr for more details.
-static Expr *EvalVal(Expr *E, SmallVectorImpl<DeclRefExpr *> &refVars) {
+static Expr *EvalVal(Expr *E, SmallVectorImpl<DeclRefExpr *> &refVars,
+ Decl *ParentDecl) {
do {
// We should only be called for evaluating non-pointer expressions, or
// expressions with a pointer type that are not used as references but instead
@@ -3258,7 +3283,7 @@
}
case Stmt::ExprWithCleanupsClass:
- return EvalVal(cast<ExprWithCleanups>(E)->getSubExpr(), refVars);
+ return EvalVal(cast<ExprWithCleanups>(E)->getSubExpr(), refVars,ParentDecl);
case Stmt::DeclRefExprClass: {
// When we hit a DeclRefExpr we are looking at code that refers to a
@@ -3266,7 +3291,11 @@
// local storage within the function, and if so, return the expression.
DeclRefExpr *DR = cast<DeclRefExpr>(E);
- if (VarDecl *V = dyn_cast<VarDecl>(DR->getDecl()))
+ if (VarDecl *V = dyn_cast<VarDecl>(DR->getDecl())) {
+ // Check if it refers to itself, e.g. "int& i = i;".
+ if (V == ParentDecl)
+ return DR;
+
if (V->hasLocalStorage()) {
if (!V->getType()->isReferenceType())
return DR;
@@ -3276,9 +3305,10 @@
if (V->hasInit()) {
// Add the reference variable to the "trail".
refVars.push_back(DR);
- return EvalVal(V->getInit(), refVars);
+ return EvalVal(V->getInit(), refVars, V);
}
}
+ }
return NULL;
}
@@ -3290,7 +3320,7 @@
UnaryOperator *U = cast<UnaryOperator>(E);
if (U->getOpcode() == UO_Deref)
- return EvalAddr(U->getSubExpr(), refVars);
+ return EvalAddr(U->getSubExpr(), refVars, ParentDecl);
return NULL;
}
@@ -3299,7 +3329,7 @@
// Array subscripts are potential references to data on the stack. We
// retrieve the DeclRefExpr* for the array variable if it indeed
// has local storage.
- return EvalAddr(cast<ArraySubscriptExpr>(E)->getBase(), refVars);
+ return EvalAddr(cast<ArraySubscriptExpr>(E)->getBase(), refVars,ParentDecl);
}
case Stmt::ConditionalOperatorClass: {
@@ -3309,10 +3339,10 @@
// Handle the GNU extension for missing LHS.
if (Expr *lhsExpr = C->getLHS())
- if (Expr *LHS = EvalVal(lhsExpr, refVars))
+ if (Expr *LHS = EvalVal(lhsExpr, refVars, ParentDecl))
return LHS;
- return EvalVal(C->getRHS(), refVars);
+ return EvalVal(C->getRHS(), refVars, ParentDecl);
}
// Accesses to members are potential references to data on the stack.
@@ -3328,13 +3358,13 @@
if (M->getMemberDecl()->getType()->isReferenceType())
return NULL;
- return EvalVal(M->getBase(), refVars);
+ return EvalVal(M->getBase(), refVars, ParentDecl);
}
case Stmt::MaterializeTemporaryExprClass:
if (Expr *Result = EvalVal(
cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr(),
- refVars))
+ refVars, ParentDecl))
return Result;
return E;
@@ -3927,9 +3957,10 @@
return;
}
- S.Diag(E->getOperatorLoc(), diag::warn_mixed_sign_comparison)
- << LHS->getType() << RHS->getType()
- << LHS->getSourceRange() << RHS->getSourceRange();
+ S.DiagRuntimeBehavior(E->getOperatorLoc(), E,
+ S.PDiag(diag::warn_mixed_sign_comparison)
+ << LHS->getType() << RHS->getType()
+ << LHS->getSourceRange() << RHS->getSourceRange());
}
/// Analyzes an attempt to assign the given value to a bitfield.
@@ -4205,7 +4236,8 @@
if (Loc.isMacroID())
Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
- << T << Loc << clang::SourceRange(CC);
+ << T << clang::SourceRange(CC)
+ << FixItHint::CreateReplacement(Loc, S.getFixItZeroLiteralForType(T));
return;
}
@@ -4457,7 +4489,7 @@
// This is also C++ [dcl.fct]p6.
if (!Param->isInvalidDecl() &&
RequireCompleteType(Param->getLocation(), Param->getType(),
- diag::err_typecheck_decl_incomplete_type)) {
+ diag::err_typecheck_decl_incomplete_type)) {
Param->setInvalidDecl();
HasInvalidParm = true;
}
@@ -4556,11 +4588,15 @@
// Don't consider sizes resulting from macro expansions or template argument
// substitution to form C89 tail-padded arrays.
- ConstantArrayTypeLoc TL =
- cast<ConstantArrayTypeLoc>(FD->getTypeSourceInfo()->getTypeLoc());
- const Expr *SizeExpr = dyn_cast<IntegerLiteral>(TL.getSizeExpr());
- if (!SizeExpr || SizeExpr->getExprLoc().isMacroID())
- return false;
+
+ TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
+ if (TInfo) {
+ ConstantArrayTypeLoc TL =
+ cast<ConstantArrayTypeLoc>(TInfo->getTypeLoc());
+ const Expr *SizeExpr = dyn_cast<IntegerLiteral>(TL.getSizeExpr());
+ if (!SizeExpr || SizeExpr->getExprLoc().isMacroID())
+ return false;
+ }
const RecordDecl *RD = dyn_cast<RecordDecl>(FD->getDeclContext());
if (!RD) return false;
Modified: cfe/branches/tooling/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaCodeComplete.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaCodeComplete.cpp Tue May 8 03:47:31 2012
@@ -1414,7 +1414,7 @@
if (!T.getLocalQualifiers()) {
// Built-in type names are constant strings.
if (const BuiltinType *BT = dyn_cast<BuiltinType>(T))
- return BT->getName(Policy);
+ return BT->getNameAsCString(Policy);
// Anonymous tag types are constant strings.
if (const TagType *TagT = dyn_cast<TagType>(T))
@@ -2842,6 +2842,7 @@
case Decl::ClassTemplatePartialSpecialization:
return CXCursor_ClassTemplatePartialSpecialization;
case Decl::UsingDirective: return CXCursor_UsingDirective;
+ case Decl::TranslationUnit: return CXCursor_TranslationUnit;
case Decl::Using:
case Decl::UnresolvedUsingValue:
@@ -3347,7 +3348,7 @@
P != PEnd;
++P) {
if (AddedProperties.insert(P->getIdentifier()))
- Results.MaybeAddResult(Result(*P, 0), CurContext);
+ Results.MaybeAddResult(Result(&*P, 0), CurContext);
}
// Add nullary methods
@@ -3362,11 +3363,11 @@
if (AddedProperties.insert(Name)) {
CodeCompletionBuilder Builder(Results.getAllocator(),
Results.getCodeCompletionTUInfo());
- AddResultTypeChunk(Context, Policy, *M, Builder);
+ AddResultTypeChunk(Context, Policy, &*M, Builder);
Builder.AddTypedTextChunk(
Results.getAllocator().CopyString(Name->getName()));
- Results.MaybeAddResult(Result(Builder.TakeString(), *M,
+ Results.MaybeAddResult(Result(Builder.TakeString(), &*M,
CCP_MemberDeclaration + CCD_MethodAsProperty),
CurContext);
}
@@ -3671,10 +3672,10 @@
for (EnumDecl::enumerator_iterator E = Enum->enumerator_begin(),
EEnd = Enum->enumerator_end();
E != EEnd; ++E) {
- if (EnumeratorsSeen.count(*E))
+ if (EnumeratorsSeen.count(&*E))
continue;
- CodeCompletionResult R(*E, Qualifier);
+ CodeCompletionResult R(&*E, Qualifier);
R.Priority = CCP_EnumInCase;
Results.AddResult(R, CurContext, 0, false);
}
@@ -4036,7 +4037,7 @@
for (DeclContext::specific_decl_iterator<NamespaceDecl>
NS(Ctx->decls_begin()), NSEnd(Ctx->decls_end());
NS != NSEnd; ++NS)
- OrigToLatest[NS->getOriginalNamespace()] = *NS;
+ OrigToLatest[NS->getOriginalNamespace()] = &*NS;
// Add the most recent definition (or extended definition) of each
// namespace to the list of results.
@@ -4192,7 +4193,7 @@
SawLastInitializer
= NumInitializers > 0 &&
Initializers[NumInitializers - 1]->isAnyMemberInitializer() &&
- Initializers[NumInitializers - 1]->getAnyMember() == *Field;
+ Initializers[NumInitializers - 1]->getAnyMember() == &*Field;
continue;
}
@@ -4209,7 +4210,7 @@
: CCP_MemberDeclaration,
CXCursor_MemberRef,
CXAvailability_Available,
- *Field));
+ &*Field));
SawLastInitializer = false;
}
Results.ExitScope();
@@ -4697,17 +4698,17 @@
for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
MEnd = Container->meth_end();
M != MEnd; ++M) {
- if ((*M)->isInstanceMethod() == WantInstanceMethods) {
+ if (M->isInstanceMethod() == WantInstanceMethods) {
// Check whether the selector identifiers we've been given are a
// subset of the identifiers for this particular method.
- if (!isAcceptableObjCMethod(*M, WantKind, SelIdents, NumSelIdents,
+ if (!isAcceptableObjCMethod(&*M, WantKind, SelIdents, NumSelIdents,
AllowSameLength))
continue;
- if (!Selectors.insert((*M)->getSelector()))
+ if (!Selectors.insert(M->getSelector()))
continue;
- Result R = Result(*M, 0);
+ Result R = Result(&*M, 0);
R.StartParameter = NumSelIdents;
R.AllParametersAreInformative = (WantKind != MK_Any);
if (!InOriginalClass)
@@ -6020,12 +6021,12 @@
for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
MEnd = Container->meth_end();
M != MEnd; ++M) {
- if ((*M)->isInstanceMethod() == WantInstanceMethods) {
+ if (M->isInstanceMethod() == WantInstanceMethods) {
if (!ReturnType.isNull() &&
- !Context.hasSameUnqualifiedType(ReturnType, (*M)->getResultType()))
+ !Context.hasSameUnqualifiedType(ReturnType, M->getResultType()))
continue;
- KnownMethods[(*M)->getSelector()] = std::make_pair(*M, InOriginalClass);
+ KnownMethods[M->getSelector()] = std::make_pair(&*M, InOriginalClass);
}
}
}
@@ -6841,7 +6842,7 @@
for (ObjCContainerDecl::prop_iterator P = Containers[I]->prop_begin(),
PEnd = Containers[I]->prop_end();
P != PEnd; ++P) {
- AddObjCKeyValueCompletions(*P, IsInstanceMethod, ReturnType, Context,
+ AddObjCKeyValueCompletions(&*P, IsInstanceMethod, ReturnType, Context,
KnownSelectors, Results);
}
}
Modified: cfe/branches/tooling/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaDecl.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaDecl.cpp Tue May 8 03:47:31 2012
@@ -470,6 +470,55 @@
return false;
}
+static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result,
+ Scope *S, CXXScopeSpec &SS,
+ IdentifierInfo *&Name,
+ SourceLocation NameLoc) {
+ Result.clear(Sema::LookupTagName);
+ SemaRef.LookupParsedName(Result, S, &SS);
+ if (TagDecl *Tag = Result.getAsSingle<TagDecl>()) {
+ const char *TagName = 0;
+ const char *FixItTagName = 0;
+ switch (Tag->getTagKind()) {
+ case TTK_Class:
+ TagName = "class";
+ FixItTagName = "class ";
+ break;
+
+ case TTK_Enum:
+ TagName = "enum";
+ FixItTagName = "enum ";
+ break;
+
+ case TTK_Struct:
+ TagName = "struct";
+ FixItTagName = "struct ";
+ break;
+
+ case TTK_Union:
+ TagName = "union";
+ FixItTagName = "union ";
+ break;
+ }
+
+ SemaRef.Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
+ << Name << TagName << SemaRef.getLangOpts().CPlusPlus
+ << FixItHint::CreateInsertion(NameLoc, FixItTagName);
+
+ LookupResult R(SemaRef, Name, NameLoc, Sema::LookupOrdinaryName);
+ if (SemaRef.LookupParsedName(R, S, &SS)) {
+ for (LookupResult::iterator I = R.begin(), IEnd = R.end();
+ I != IEnd; ++I)
+ SemaRef.Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
+ << Name << TagName;
+ }
+ return true;
+ }
+
+ Result.clear(Sema::LookupOrdinaryName);
+ return false;
+}
+
Sema::NameClassification Sema::ClassifyName(Scope *S,
CXXScopeSpec &SS,
IdentifierInfo *&Name,
@@ -533,41 +582,9 @@
// In C, we first see whether there is a tag type by the same name, in
// which case it's likely that the user just forget to write "enum",
// "struct", or "union".
- if (!getLangOpts().CPlusPlus && !SecondTry) {
- Result.clear(LookupTagName);
- LookupParsedName(Result, S, &SS);
- if (TagDecl *Tag = Result.getAsSingle<TagDecl>()) {
- const char *TagName = 0;
- const char *FixItTagName = 0;
- switch (Tag->getTagKind()) {
- case TTK_Class:
- TagName = "class";
- FixItTagName = "class ";
- break;
-
- case TTK_Enum:
- TagName = "enum";
- FixItTagName = "enum ";
- break;
-
- case TTK_Struct:
- TagName = "struct";
- FixItTagName = "struct ";
- break;
-
- case TTK_Union:
- TagName = "union";
- FixItTagName = "union ";
- break;
- }
-
- Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
- << Name << TagName << getLangOpts().CPlusPlus
- << FixItHint::CreateInsertion(NameLoc, FixItTagName);
- break;
- }
-
- Result.clear(LookupOrdinaryName);
+ if (!getLangOpts().CPlusPlus && !SecondTry &&
+ isTagTypeWithMissingTag(*this, Result, S, SS, Name, NameLoc)) {
+ break;
}
// Perform typo correction to determine if there is another name that is
@@ -740,7 +757,7 @@
if (TypeDecl *Type = dyn_cast<TypeDecl>(FirstDecl)) {
DiagnoseUseOfDecl(Type, NameLoc);
QualType T = Context.getTypeDeclType(Type);
- return ParsedType::make(T);
+ return ParsedType::make(T);
}
ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(FirstDecl);
@@ -764,6 +781,23 @@
QualType T = Context.getObjCInterfaceType(Class);
return ParsedType::make(T);
}
+
+ // Check for a tag type hidden by a non-type decl in a few cases where it
+ // seems likely a type is wanted instead of the non-type that was found.
+ if (!getLangOpts().ObjC1 && FirstDecl && !isa<ClassTemplateDecl>(FirstDecl) &&
+ !isa<TypeAliasTemplateDecl>(FirstDecl)) {
+ bool NextIsOp = NextToken.is(tok::amp) || NextToken.is(tok::star);
+ if ((NextToken.is(tok::identifier) ||
+ (NextIsOp && FirstDecl->isFunctionOrFunctionTemplate())) &&
+ isTagTypeWithMissingTag(*this, Result, S, SS, Name, NameLoc)) {
+ FirstDecl = (*Result.begin())->getUnderlyingDecl();
+ if (TypeDecl *Type = dyn_cast<TypeDecl>(FirstDecl)) {
+ DiagnoseUseOfDecl(Type, NameLoc);
+ QualType T = Context.getTypeDeclType(Type);
+ return ParsedType::make(T);
+ }
+ }
+ }
if (!Result.empty() && (*Result.begin())->isCXXClassMember())
return BuildPossibleImplicitMemberExpr(SS, SourceLocation(), Result, 0);
@@ -1599,6 +1633,13 @@
/// attribute.
static bool
DeclHasAttr(const Decl *D, const Attr *A) {
+ // There can be multiple AvailabilityAttr in a Decl. Make sure we copy
+ // all of them. It is mergeAvailabilityAttr in SemaDeclAttr.cpp that is
+ // responsible for making sure they are consistent.
+ const AvailabilityAttr *AA = dyn_cast<AvailabilityAttr>(A);
+ if (AA)
+ return false;
+
const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
for (Decl::attr_iterator i = D->attr_begin(), e = D->attr_end(); i != e; ++i)
@@ -3225,7 +3266,7 @@
Decl *Dcl = HandleDeclarator(S, D, MultiTemplateParamsArg(*this));
if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() &&
- Dcl->getDeclContext()->isFileContext())
+ Dcl && Dcl->getDeclContext()->isFileContext())
Dcl->setTopLevelDeclInObjCContainer();
return Dcl;
@@ -4418,7 +4459,7 @@
if (NewVD->isConstexpr() && !T->isDependentType() &&
RequireLiteralType(NewVD->getLocation(), T,
- PDiag(diag::err_constexpr_var_non_literal))) {
+ diag::err_constexpr_var_non_literal)) {
NewVD->setInvalidDecl();
return false;
}
@@ -5082,12 +5123,14 @@
(RD->isEmpty() || RD->hasUserProvidedDefaultConstructor()))
Diag(C.Loc, diag::note_empty_parens_default_ctor)
<< FixItHint::CreateRemoval(ParenRange);
- else if (const char *Init = getFixItZeroInitializerForType(T))
- Diag(C.Loc, diag::note_empty_parens_zero_initialize)
- << FixItHint::CreateReplacement(ParenRange, Init);
- else if (LangOpts.CPlusPlus0x)
- Diag(C.Loc, diag::note_empty_parens_zero_initialize)
- << FixItHint::CreateReplacement(ParenRange, "{}");
+ else {
+ std::string Init = getFixItZeroInitializerForType(T);
+ if (Init.empty() && LangOpts.CPlusPlus0x)
+ Init = "{}";
+ if (!Init.empty())
+ Diag(C.Loc, diag::note_empty_parens_zero_initialize)
+ << FixItHint::CreateReplacement(ParenRange, Init);
+ }
}
}
@@ -7353,7 +7396,7 @@
if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
for (EnumDecl::enumerator_iterator EI = ED->enumerator_begin(),
EE = ED->enumerator_end(); EI != EE; ++EI)
- PushOnScopeChains(*EI, FnBodyScope, /*AddToContext=*/false);
+ PushOnScopeChains(&*EI, FnBodyScope, /*AddToContext=*/false);
}
}
}
@@ -7635,7 +7678,7 @@
SourceLocation(), SourceLocation(),
SourceLocation(),
EST_None, SourceLocation(),
- 0, 0, 0, 0, 0, Loc, Loc, D),
+ 0, 0, 0, 0, Loc, Loc, D),
DS.getAttributes(),
SourceLocation());
D.SetIdentifier(&II, Loc);
@@ -9178,7 +9221,7 @@
if (RD->hasUserDeclaredConstructor()) {
typedef CXXRecordDecl::ctor_iterator ctor_iter;
for (ctor_iter CI = RD->ctor_begin(), CE = RD->ctor_end(); CI != CE; ++CI)
- if (DiagnoseNontrivialUserProvidedCtor(*this, QT, *CI, member))
+ if (DiagnoseNontrivialUserProvidedCtor(*this, QT, &*CI, member))
return;
// No user-provided constructors; look for constructor templates.
@@ -9295,12 +9338,12 @@
typedef RecordDecl::field_iterator field_iter;
for (field_iter fi = RD->field_begin(), fe = RD->field_end(); fi != fe;
++fi) {
- QualType EltTy = Context.getBaseElementType((*fi)->getType());
+ QualType EltTy = Context.getBaseElementType(fi->getType());
if (const RecordType *EltRT = EltTy->getAs<RecordType>()) {
CXXRecordDecl* EltRD = cast<CXXRecordDecl>(EltRT->getDecl());
if (!(EltRD->*hasTrivial)()) {
- SourceLocation FLoc = (*fi)->getLocation();
+ SourceLocation FLoc = fi->getLocation();
Diag(FLoc, diag::note_nontrivial_has_nontrivial) << QT << 0 << member;
DiagnoseNontrivial(EltRT, member);
return;
@@ -9316,7 +9359,7 @@
case Qualifiers::OCL_Autoreleasing:
case Qualifiers::OCL_Weak:
case Qualifiers::OCL_Strong:
- Diag((*fi)->getLocation(), diag::note_nontrivial_objc_ownership)
+ Diag(fi->getLocation(), diag::note_nontrivial_objc_ownership)
<< QT << EltTy.getObjCLifetime();
return;
}
Modified: cfe/branches/tooling/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaDeclAttr.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaDeclAttr.cpp Tue May 8 03:47:31 2012
@@ -14,6 +14,7 @@
#include "clang/Sema/SemaInternal.h"
#include "TargetAttributesSema.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclObjC.h"
@@ -241,26 +242,23 @@
// Check to see if the type is a smart pointer of some kind. We assume
// it's a smart pointer if it defines both operator-> and operator*.
-static bool threadSafetyCheckIsSmartPointer(Sema &S, const QualType QT) {
- if (const RecordType *RT = QT->getAs<RecordType>()) {
- DeclContextLookupConstResult Res1 = RT->getDecl()->lookup(
- S.Context.DeclarationNames.getCXXOperatorName(OO_Star));
- if (Res1.first == Res1.second)
- return false;
+static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType* RT) {
+ DeclContextLookupConstResult Res1 = RT->getDecl()->lookup(
+ S.Context.DeclarationNames.getCXXOperatorName(OO_Star));
+ if (Res1.first == Res1.second)
+ return false;
- DeclContextLookupConstResult Res2 = RT->getDecl()->lookup(
- S.Context.DeclarationNames.getCXXOperatorName(OO_Arrow));
- if (Res2.first != Res2.second)
- return true;
- }
- return false;
+ DeclContextLookupConstResult Res2 = RT->getDecl()->lookup(
+ S.Context.DeclarationNames.getCXXOperatorName(OO_Arrow));
+ if (Res2.first == Res2.second)
+ return false;
+
+ return true;
}
-///
/// \brief Check if passed in Decl is a pointer type.
/// Note that this function may produce an error message.
/// \return true if the Decl is a pointer type; false otherwise
-///
static bool threadSafetyCheckIsPointer(Sema &S, const Decl *D,
const AttributeList &Attr) {
if (const ValueDecl *vd = dyn_cast<ValueDecl>(D)) {
@@ -268,8 +266,16 @@
if (QT->isAnyPointerType())
return true;
- if (threadSafetyCheckIsSmartPointer(S, QT))
- return true;
+ if (const RecordType *RT = QT->getAs<RecordType>()) {
+ // If it's an incomplete type, it could be a smart pointer; skip it.
+ // (We don't want to force template instantiation if we can avoid it,
+ // since that would alter the order in which templates are instantiated.)
+ if (RT->isIncompleteType())
+ return true;
+
+ if (threadSafetyCheckIsSmartPointer(S, RT))
+ return true;
+ }
S.Diag(Attr.getLoc(), diag::warn_thread_attribute_decl_not_pointer)
<< Attr.getName()->getName() << QT;
@@ -293,6 +299,16 @@
return 0;
}
+
+static bool checkBaseClassIsLockableCallback(const CXXBaseSpecifier *Specifier,
+ CXXBasePath &Path, void *Unused) {
+ const RecordType *RT = Specifier->getType()->getAs<RecordType>();
+ if (RT->getDecl()->getAttr<LockableAttr>())
+ return true;
+ return false;
+}
+
+
/// \brief Thread Safety Analysis: Checks that the passed in RecordType
/// resolves to a lockable object.
static void checkForLockableRecord(Sema &S, Decl *D, const AttributeList &Attr,
@@ -305,15 +321,30 @@
<< Attr.getName() << Ty.getAsString();
return;
}
+
// Don't check for lockable if the class hasn't been defined yet.
if (RT->isIncompleteType())
return;
- // Warn if the type is not lockable.
- if (!RT->getDecl()->getAttr<LockableAttr>()) {
- S.Diag(Attr.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
- << Attr.getName() << Ty.getAsString();
+
+ // Allow smart pointers to be used as lockable objects.
+ // FIXME -- Check the type that the smart pointer points to.
+ if (threadSafetyCheckIsSmartPointer(S, RT))
+ return;
+
+ // Check if the type is lockable.
+ RecordDecl *RD = RT->getDecl();
+ if (RD->getAttr<LockableAttr>())
return;
+
+ // Else check if any base classes are lockable.
+ if (CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
+ CXXBasePaths BPaths(false, false);
+ if (CRD->lookupInBases(checkBaseClassIsLockableCallback, 0, BPaths))
+ return;
}
+
+ S.Diag(Attr.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
+ << Attr.getName() << Ty.getAsString();
}
/// \brief Thread Safety Analysis: Checks that all attribute arguments, starting
@@ -681,9 +712,14 @@
return;
// check that the argument is lockable object
- checkForLockableRecord(S, D, Attr, Arg->getType());
+ SmallVector<Expr*, 1> Args;
+ checkAttrArgsAreLockableObjs(S, D, Attr, Args);
+ unsigned Size = Args.size();
+ if (Size == 0)
+ return;
- D->addAttr(::new (S.Context) LockReturnedAttr(Attr.getRange(), S.Context, Arg));
+ D->addAttr(::new (S.Context) LockReturnedAttr(Attr.getRange(), S.Context,
+ Args[0]));
}
static void handleLocksExcludedAttr(Sema &S, Decl *D,
@@ -1654,64 +1690,143 @@
Attr.getRange(), S.Context));
}
-static void handleAvailabilityAttr(Sema &S, Decl *D,
- const AttributeList &Attr) {
- IdentifierInfo *Platform = Attr.getParameterName();
- SourceLocation PlatformLoc = Attr.getParameterLoc();
-
+static bool checkAvailabilityAttr(Sema &S, SourceRange Range,
+ IdentifierInfo *Platform,
+ VersionTuple Introduced,
+ VersionTuple Deprecated,
+ VersionTuple Obsoleted) {
StringRef PlatformName
= AvailabilityAttr::getPrettyPlatformName(Platform->getName());
- if (PlatformName.empty()) {
- S.Diag(PlatformLoc, diag::warn_availability_unknown_platform)
- << Platform;
-
+ if (PlatformName.empty())
PlatformName = Platform->getName();
- }
-
- AvailabilityChange Introduced = Attr.getAvailabilityIntroduced();
- AvailabilityChange Deprecated = Attr.getAvailabilityDeprecated();
- AvailabilityChange Obsoleted = Attr.getAvailabilityObsoleted();
- bool IsUnavailable = Attr.getUnavailableLoc().isValid();
// Ensure that Introduced <= Deprecated <= Obsoleted (although not all
// of these steps are needed).
- if (Introduced.isValid() && Deprecated.isValid() &&
- !(Introduced.Version <= Deprecated.Version)) {
- S.Diag(Introduced.KeywordLoc, diag::warn_availability_version_ordering)
- << 1 << PlatformName << Deprecated.Version.getAsString()
- << 0 << Introduced.Version.getAsString();
- return;
+ if (!Introduced.empty() && !Deprecated.empty() &&
+ !(Introduced <= Deprecated)) {
+ S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
+ << 1 << PlatformName << Deprecated.getAsString()
+ << 0 << Introduced.getAsString();
+ return true;
}
- if (Introduced.isValid() && Obsoleted.isValid() &&
- !(Introduced.Version <= Obsoleted.Version)) {
- S.Diag(Introduced.KeywordLoc, diag::warn_availability_version_ordering)
- << 2 << PlatformName << Obsoleted.Version.getAsString()
- << 0 << Introduced.Version.getAsString();
- return;
+ if (!Introduced.empty() && !Obsoleted.empty() &&
+ !(Introduced <= Obsoleted)) {
+ S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
+ << 2 << PlatformName << Obsoleted.getAsString()
+ << 0 << Introduced.getAsString();
+ return true;
}
- if (Deprecated.isValid() && Obsoleted.isValid() &&
- !(Deprecated.Version <= Obsoleted.Version)) {
- S.Diag(Deprecated.KeywordLoc, diag::warn_availability_version_ordering)
- << 2 << PlatformName << Obsoleted.Version.getAsString()
- << 1 << Deprecated.Version.getAsString();
- return;
+ if (!Deprecated.empty() && !Obsoleted.empty() &&
+ !(Deprecated <= Obsoleted)) {
+ S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
+ << 2 << PlatformName << Obsoleted.getAsString()
+ << 1 << Deprecated.getAsString();
+ return true;
}
+ return false;
+}
+
+static void mergeAvailabilityAttr(Sema &S, Decl *D, SourceRange Range,
+ IdentifierInfo *Platform,
+ VersionTuple Introduced,
+ VersionTuple Deprecated,
+ VersionTuple Obsoleted,
+ bool IsUnavailable,
+ StringRef Message) {
+ VersionTuple MergedIntroduced;
+ VersionTuple MergedDeprecated;
+ VersionTuple MergedObsoleted;
+ bool FoundAny = false;
+
+ for (specific_attr_iterator<AvailabilityAttr>
+ i = D->specific_attr_begin<AvailabilityAttr>(),
+ e = D->specific_attr_end<AvailabilityAttr>();
+ i != e ; ++i) {
+ const AvailabilityAttr *OldAA = *i;
+ IdentifierInfo *OldPlatform = OldAA->getPlatform();
+ if (OldPlatform != Platform)
+ continue;
+ FoundAny = true;
+ VersionTuple OldIntroduced = OldAA->getIntroduced();
+ VersionTuple OldDeprecated = OldAA->getDeprecated();
+ VersionTuple OldObsoleted = OldAA->getObsoleted();
+ bool OldIsUnavailable = OldAA->getUnavailable();
+ StringRef OldMessage = OldAA->getMessage();
+
+ if ((!OldIntroduced.empty() && !Introduced.empty() &&
+ OldIntroduced != Introduced) ||
+ (!OldDeprecated.empty() && !Deprecated.empty() &&
+ OldDeprecated != Deprecated) ||
+ (!OldObsoleted.empty() && !Obsoleted.empty() &&
+ OldObsoleted != Obsoleted) ||
+ (OldIsUnavailable != IsUnavailable) ||
+ (OldMessage != Message)) {
+ S.Diag(Range.getBegin(), diag::warn_mismatched_availability);
+ S.Diag(OldAA->getLocation(), diag::note_previous_attribute);
+ return;
+ }
+ if (MergedIntroduced.empty())
+ MergedIntroduced = OldIntroduced;
+ if (MergedDeprecated.empty())
+ MergedDeprecated = OldDeprecated;
+ if (MergedObsoleted.empty())
+ MergedObsoleted = OldObsoleted;
+ }
+
+ if (FoundAny &&
+ MergedIntroduced == Introduced &&
+ MergedDeprecated == Deprecated &&
+ MergedObsoleted == Obsoleted)
+ return;
+
+ if (MergedIntroduced.empty())
+ MergedIntroduced = Introduced;
+ if (MergedDeprecated.empty())
+ MergedDeprecated = Deprecated;
+ if (MergedObsoleted.empty())
+ MergedObsoleted = Obsoleted;
+
+ if (!checkAvailabilityAttr(S, Range, Platform, MergedIntroduced,
+ MergedDeprecated, MergedObsoleted)) {
+ D->addAttr(::new (S.Context) AvailabilityAttr(Range, S.Context,
+ Platform,
+ Introduced,
+ Deprecated,
+ Obsoleted,
+ IsUnavailable,
+ Message));
+ }
+}
+
+static void handleAvailabilityAttr(Sema &S, Decl *D,
+ const AttributeList &Attr) {
+ IdentifierInfo *Platform = Attr.getParameterName();
+ SourceLocation PlatformLoc = Attr.getParameterLoc();
+
+ if (AvailabilityAttr::getPrettyPlatformName(Platform->getName()).empty())
+ S.Diag(PlatformLoc, diag::warn_availability_unknown_platform)
+ << Platform;
+
+ AvailabilityChange Introduced = Attr.getAvailabilityIntroduced();
+ AvailabilityChange Deprecated = Attr.getAvailabilityDeprecated();
+ AvailabilityChange Obsoleted = Attr.getAvailabilityObsoleted();
+ bool IsUnavailable = Attr.getUnavailableLoc().isValid();
StringRef Str;
const StringLiteral *SE =
dyn_cast_or_null<const StringLiteral>(Attr.getMessageExpr());
if (SE)
Str = SE->getString();
-
- D->addAttr(::new (S.Context) AvailabilityAttr(Attr.getRange(), S.Context,
- Platform,
- Introduced.Version,
- Deprecated.Version,
- Obsoleted.Version,
- IsUnavailable,
- Str));
+
+ mergeAvailabilityAttr(S, D, Attr.getRange(),
+ Platform,
+ Introduced.Version,
+ Deprecated.Version,
+ Obsoleted.Version,
+ IsUnavailable,
+ Str);
}
static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
@@ -1752,11 +1867,20 @@
return;
}
- VisibilityAttr *PrevAttr = D->getCanonicalDecl()->getAttr<VisibilityAttr>();
+ // Find the last Decl that has an attribute.
+ VisibilityAttr *PrevAttr = 0;
+ assert(D->redecls_begin() == D);
+ for (Decl::redecl_iterator I = D->redecls_begin(), E = D->redecls_end();
+ I != E; ++I) {
+ PrevAttr = I->getAttr<VisibilityAttr>() ;
+ if (PrevAttr)
+ break;
+ }
+
if (PrevAttr) {
VisibilityAttr::VisibilityType PrevVisibility = PrevAttr->getVisibility();
if (PrevVisibility != type) {
- S.Diag(Attr.getLoc(), diag::err_mismatched_visibilit);
+ S.Diag(Attr.getLoc(), diag::err_mismatched_visibility);
S.Diag(PrevAttr->getLocation(), diag::note_previous_attribute);
return;
}
@@ -2572,7 +2696,7 @@
return;
}
- FieldDecl *FirstField = *Field;
+ FieldDecl *FirstField = &*Field;
QualType FirstType = FirstField->getType();
if (FirstType->hasFloatingRepresentation() || FirstType->isVectorType()) {
S.Diag(FirstField->getLocation(),
@@ -2664,10 +2788,10 @@
SourceLocation AttrLoc = AttrRange.getBegin();
// FIXME: Cache the number on the Attr object?
llvm::APSInt Alignment(32);
- ExprResult ICE =
- VerifyIntegerConstantExpression(E, &Alignment,
- PDiag(diag::err_attribute_argument_not_int) << "aligned",
- /*AllowFold*/ false);
+ ExprResult ICE
+ = VerifyIntegerConstantExpression(E, &Alignment,
+ diag::err_aligned_attribute_argument_not_int,
+ /*AllowFold*/ false);
if (ICE.isInvalid())
return;
if (!llvm::isPowerOf2_64(Alignment.getZExtValue())) {
@@ -3862,8 +3986,12 @@
void Sema::ProcessDeclAttributeList(Scope *S, Decl *D,
const AttributeList *AttrList,
bool NonInheritable, bool Inheritable) {
+ SmallVector<const AttributeList*, 4> attrs;
for (const AttributeList* l = AttrList; l; l = l->getNext()) {
- ProcessDeclAttribute(*this, S, D, *l, NonInheritable, Inheritable);
+ attrs.push_back(l);
+ }
+ for (int i = attrs.size() - 1; i >= 0; --i) {
+ ProcessDeclAttribute(*this, S, D, *attrs[i], NonInheritable, Inheritable);
}
// GCC accepts
@@ -4074,57 +4202,29 @@
diag.Triggered = true;
}
-// This duplicates a vector push_back but hides the need to know the
-// size of the type.
-void Sema::DelayedDiagnostics::add(const DelayedDiagnostic &diag) {
- assert(StackSize <= StackCapacity);
-
- // Grow the stack if necessary.
- if (StackSize == StackCapacity) {
- unsigned newCapacity = 2 * StackCapacity + 2;
- char *newBuffer = new char[newCapacity * sizeof(DelayedDiagnostic)];
- const char *oldBuffer = (const char*) Stack;
-
- if (StackCapacity)
- memcpy(newBuffer, oldBuffer, StackCapacity * sizeof(DelayedDiagnostic));
-
- delete[] oldBuffer;
- Stack = reinterpret_cast<sema::DelayedDiagnostic*>(newBuffer);
- StackCapacity = newCapacity;
- }
-
- assert(StackSize < StackCapacity);
- new (&Stack[StackSize++]) DelayedDiagnostic(diag);
-}
-
-void Sema::DelayedDiagnostics::popParsingDecl(Sema &S, ParsingDeclState state,
- Decl *decl) {
- DelayedDiagnostics &DD = S.DelayedDiagnostics;
-
- // Check the invariants.
- assert(DD.StackSize >= state.SavedStackSize);
- assert(state.SavedStackSize >= DD.ActiveStackBase);
- assert(DD.ParsingDepth > 0);
-
- // Drop the parsing depth.
- DD.ParsingDepth--;
-
- // If there are no active diagnostics, we're done.
- if (DD.StackSize == DD.ActiveStackBase)
- return;
-
- // We only want to actually emit delayed diagnostics when we
- // successfully parsed a decl.
- if (decl) {
- // We emit all the active diagnostics, not just those starting
- // from the saved state. The idea is this: we get one push for a
- // decl spec and another for each declarator; in a decl group like:
- // deprecated_typedef foo, *bar, baz();
- // only the declarator pops will be passed decls. This is correct;
- // we really do need to consider delayed diagnostics from the decl spec
- // for each of the different declarations.
- for (unsigned i = DD.ActiveStackBase, e = DD.StackSize; i != e; ++i) {
- DelayedDiagnostic &diag = DD.Stack[i];
+void Sema::PopParsingDeclaration(ParsingDeclState state, Decl *decl) {
+ assert(DelayedDiagnostics.getCurrentPool());
+ DelayedDiagnosticPool &poppedPool = *DelayedDiagnostics.getCurrentPool();
+ DelayedDiagnostics.popWithoutEmitting(state);
+
+ // When delaying diagnostics to run in the context of a parsed
+ // declaration, we only want to actually emit anything if parsing
+ // succeeds.
+ if (!decl) return;
+
+ // We emit all the active diagnostics in this pool or any of its
+ // parents. In general, we'll get one pool for the decl spec
+ // and a child pool for each declarator; in a decl group like:
+ // deprecated_typedef foo, *bar, baz();
+ // only the declarator pops will be passed decls. This is correct;
+ // we really do need to consider delayed diagnostics from the decl spec
+ // for each of the different declarations.
+ const DelayedDiagnosticPool *pool = &poppedPool;
+ do {
+ for (DelayedDiagnosticPool::pool_iterator
+ i = pool->pool_begin(), e = pool->pool_end(); i != e; ++i) {
+ // This const_cast is a bit lame. Really, Triggered should be mutable.
+ DelayedDiagnostic &diag = const_cast<DelayedDiagnostic&>(*i);
if (diag.Triggered)
continue;
@@ -4132,25 +4232,28 @@
case DelayedDiagnostic::Deprecation:
// Don't bother giving deprecation diagnostics if the decl is invalid.
if (!decl->isInvalidDecl())
- S.HandleDelayedDeprecationCheck(diag, decl);
+ HandleDelayedDeprecationCheck(diag, decl);
break;
case DelayedDiagnostic::Access:
- S.HandleDelayedAccessCheck(diag, decl);
+ HandleDelayedAccessCheck(diag, decl);
break;
case DelayedDiagnostic::ForbiddenType:
- handleDelayedForbiddenType(S, diag, decl);
+ handleDelayedForbiddenType(*this, diag, decl);
break;
}
}
- }
-
- // Destroy all the delayed diagnostics we're about to pop off.
- for (unsigned i = state.SavedStackSize, e = DD.StackSize; i != e; ++i)
- DD.Stack[i].Destroy();
+ } while ((pool = pool->getParent()));
+}
- DD.StackSize = state.SavedStackSize;
+/// Given a set of delayed diagnostics, re-emit them as if they had
+/// been delayed in the current context instead of in the given pool.
+/// Essentially, this just moves them to the current pool.
+void Sema::redelayDiagnostics(DelayedDiagnosticPool &pool) {
+ DelayedDiagnosticPool *curPool = DelayedDiagnostics.getCurrentPool();
+ assert(curPool && "re-emitting in undelayed context not supported");
+ curPool->steal(pool);
}
static bool isDeclDeprecated(Decl *D) {
Modified: cfe/branches/tooling/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaDeclCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaDeclCXX.cpp Tue May 8 03:47:31 2012
@@ -667,9 +667,9 @@
SourceLocation ParamLoc = PD->getLocation();
if (!(*i)->isDependentType() &&
SemaRef.RequireLiteralType(ParamLoc, *i,
- SemaRef.PDiag(diag::err_constexpr_non_literal_param)
- << ArgIndex+1 << PD->getSourceRange()
- << isa<CXXConstructorDecl>(FD)))
+ diag::err_constexpr_non_literal_param,
+ ArgIndex+1, PD->getSourceRange(),
+ isa<CXXConstructorDecl>(FD)))
return false;
}
return true;
@@ -725,7 +725,7 @@
QualType RT = NewFD->getResultType();
if (!RT->isDependentType() &&
RequireLiteralType(NewFD->getLocation(), RT,
- PDiag(diag::err_constexpr_non_literal_return)))
+ diag::err_constexpr_non_literal_return))
return false;
}
@@ -833,8 +833,8 @@
I != E; ++I)
// If an anonymous union contains an anonymous struct of which any member
// is initialized, all members must be initialized.
- if (!RD->isUnion() || Inits.count(*I))
- CheckConstexprCtorInitializer(SemaRef, Dcl, *I, Inits, Diagnosed);
+ if (!RD->isUnion() || Inits.count(&*I))
+ CheckConstexprCtorInitializer(SemaRef, Dcl, &*I, Inits, Diagnosed);
}
}
@@ -920,7 +920,7 @@
unsigned Fields = 0;
for (CXXRecordDecl::field_iterator I = RD->field_begin(),
E = RD->field_end(); I != E; ++I, ++Fields) {
- if ((*I)->isAnonymousStructOrUnion()) {
+ if (I->isAnonymousStructOrUnion()) {
AnyAnonStructUnionMembers = true;
break;
}
@@ -943,7 +943,7 @@
bool Diagnosed = false;
for (CXXRecordDecl::field_iterator I = RD->field_begin(),
E = RD->field_end(); I != E; ++I)
- CheckConstexprCtorInitializer(*this, Dcl, *I, Inits, Diagnosed);
+ CheckConstexprCtorInitializer(*this, Dcl, &*I, Inits, Diagnosed);
if (Diagnosed)
return false;
}
@@ -1055,8 +1055,7 @@
// The class-name in a base-specifier shall not be an incompletely
// defined class.
if (RequireCompleteType(BaseLoc, BaseType,
- PDiag(diag::err_incomplete_base_class)
- << SpecifierRange)) {
+ diag::err_incomplete_base_class, SpecifierRange)) {
Class->setInvalidDecl();
return 0;
}
@@ -3089,7 +3088,7 @@
if (Field->isUnnamedBitfield())
continue;
- IdealInitKeys.push_back(GetKeyForTopLevelField(*Field));
+ IdealInitKeys.push_back(GetKeyForTopLevelField(&*Field));
}
unsigned NumIdealInits = IdealInitKeys.size();
@@ -3289,7 +3288,7 @@
// Non-static data members.
for (CXXRecordDecl::field_iterator I = ClassDecl->field_begin(),
E = ClassDecl->field_end(); I != E; ++I) {
- FieldDecl *Field = *I;
+ FieldDecl *Field = &*I;
if (Field->isInvalidDecl())
continue;
@@ -3397,19 +3396,32 @@
bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T,
unsigned DiagID, AbstractDiagSelID SelID) {
- if (SelID == -1)
- return RequireNonAbstractType(Loc, T, PDiag(DiagID));
- else
- return RequireNonAbstractType(Loc, T, PDiag(DiagID) << SelID);
+ class NonAbstractTypeDiagnoser : public TypeDiagnoser {
+ unsigned DiagID;
+ AbstractDiagSelID SelID;
+
+ public:
+ NonAbstractTypeDiagnoser(unsigned DiagID, AbstractDiagSelID SelID)
+ : TypeDiagnoser(DiagID == 0), DiagID(DiagID), SelID(SelID) { }
+
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ if (SelID == -1)
+ S.Diag(Loc, DiagID) << T;
+ else
+ S.Diag(Loc, DiagID) << SelID << T;
+ }
+ } Diagnoser(DiagID, SelID);
+
+ return RequireNonAbstractType(Loc, T, Diagnoser);
}
bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD) {
+ TypeDiagnoser &Diagnoser) {
if (!getLangOpts().CPlusPlus)
return false;
if (const ArrayType *AT = Context.getAsArrayType(T))
- return RequireNonAbstractType(Loc, AT->getElementType(), PD);
+ return RequireNonAbstractType(Loc, AT->getElementType(), Diagnoser);
if (const PointerType *PT = T->getAs<PointerType>()) {
// Find the innermost pointer type.
@@ -3417,7 +3429,7 @@
PT = T;
if (const ArrayType *AT = Context.getAsArrayType(PT->getPointeeType()))
- return RequireNonAbstractType(Loc, AT->getElementType(), PD);
+ return RequireNonAbstractType(Loc, AT->getElementType(), Diagnoser);
}
const RecordType *RT = T->getAs<RecordType>();
@@ -3436,7 +3448,7 @@
if (!RD->isAbstract())
return false;
- Diag(Loc, PD) << RD->getDeclName();
+ Diagnoser.diagnose(*this, Loc, T);
DiagnoseAbstractType(RD);
return true;
@@ -3732,8 +3744,8 @@
for (CXXRecordDecl::method_iterator M = Record->method_begin(),
MEnd = Record->method_end();
M != MEnd; ++M) {
- if (!(*M)->isStatic())
- DiagnoseHiddenVirtualMethods(Record, *M);
+ if (!M->isStatic())
+ DiagnoseHiddenVirtualMethods(Record, &*M);
}
}
@@ -3762,8 +3774,8 @@
case TSK_Undeclared:
case TSK_ExplicitSpecialization:
- RequireLiteralType((*M)->getLocation(), Context.getRecordType(Record),
- PDiag(diag::err_constexpr_method_non_literal));
+ RequireLiteralType(M->getLocation(), Context.getRecordType(Record),
+ diag::err_constexpr_method_non_literal);
break;
}
@@ -3791,30 +3803,30 @@
ME = Record->method_end();
MI != ME; ++MI) {
if (!MI->isInvalidDecl() && MI->isExplicitlyDefaulted()) {
- switch (getSpecialMember(*MI)) {
+ switch (getSpecialMember(&*MI)) {
case CXXDefaultConstructor:
CheckExplicitlyDefaultedDefaultConstructor(
- cast<CXXConstructorDecl>(*MI));
+ cast<CXXConstructorDecl>(&*MI));
break;
case CXXDestructor:
- CheckExplicitlyDefaultedDestructor(cast<CXXDestructorDecl>(*MI));
+ CheckExplicitlyDefaultedDestructor(cast<CXXDestructorDecl>(&*MI));
break;
case CXXCopyConstructor:
- CheckExplicitlyDefaultedCopyConstructor(cast<CXXConstructorDecl>(*MI));
+ CheckExplicitlyDefaultedCopyConstructor(cast<CXXConstructorDecl>(&*MI));
break;
case CXXCopyAssignment:
- CheckExplicitlyDefaultedCopyAssignment(*MI);
+ CheckExplicitlyDefaultedCopyAssignment(&*MI);
break;
case CXXMoveConstructor:
- CheckExplicitlyDefaultedMoveConstructor(cast<CXXConstructorDecl>(*MI));
+ CheckExplicitlyDefaultedMoveConstructor(cast<CXXConstructorDecl>(&*MI));
break;
case CXXMoveAssignment:
- CheckExplicitlyDefaultedMoveAssignment(*MI);
+ CheckExplicitlyDefaultedMoveAssignment(&*MI);
break;
case CXXInvalid:
@@ -4549,7 +4561,7 @@
(!FieldRecord || !FieldRecord->hasUserProvidedDefaultConstructor())) {
if (Diagnose)
S.Diag(FD->getLocation(), diag::note_deleted_default_ctor_uninit_field)
- << MD->getParent() << FD << FieldType << /*Const*/1;
+ << MD->getParent() << FD << FD->getType() << /*Const*/1;
return true;
}
@@ -4577,7 +4589,7 @@
// -- a non-static data member of const non-class type (or array thereof)
if (Diagnose)
S.Diag(FD->getLocation(), diag::note_deleted_assign_field)
- << IsMove << MD->getParent() << FD << FieldType << /*Const*/1;
+ << IsMove << MD->getParent() << FD << FD->getType() << /*Const*/1;
return true;
}
}
@@ -4599,7 +4611,7 @@
CXXRecordDecl *UnionFieldRecord = UnionFieldType->getAsCXXRecordDecl();
if (UnionFieldRecord &&
- shouldDeleteForClassSubobject(UnionFieldRecord, *UI))
+ shouldDeleteForClassSubobject(UnionFieldRecord, &*UI))
return true;
}
@@ -4736,7 +4748,7 @@
for (CXXRecordDecl::field_iterator FI = RD->field_begin(),
FE = RD->field_end(); FI != FE; ++FI)
if (!FI->isInvalidDecl() && !FI->isUnnamedBitfield() &&
- SMI.shouldDeleteForField(*FI))
+ SMI.shouldDeleteForField(&*FI))
return true;
if (SMI.shouldDeleteForAllConstMembers())
@@ -5925,10 +5937,12 @@
case UnqualifiedId::IK_ConstructorName:
case UnqualifiedId::IK_ConstructorTemplateId:
- // C++0x inherited constructors.
+ // C++11 inheriting constructors.
Diag(Name.getLocStart(),
getLangOpts().CPlusPlus0x ?
- diag::warn_cxx98_compat_using_decl_constructor :
+ // FIXME: Produce warn_cxx98_compat_using_decl_constructor
+ // instead once inheriting constructors work.
+ diag::err_using_decl_constructor_unsupported :
diag::err_using_decl_constructor)
<< SS.getRange();
@@ -7086,7 +7100,7 @@
// results from omitting any ellipsis parameter specification and
// successively omitting parameters with a default argument from the
// end of the parameter-type-list.
- CXXConstructorDecl *BaseCtor = *CtorIt;
+ CXXConstructorDecl *BaseCtor = &*CtorIt;
bool CanBeCopyOrMove = BaseCtor->isCopyOrMoveConstructor();
const FunctionProtoType *BaseCtorType =
BaseCtor->getType()->getAs<FunctionProtoType>();
@@ -7639,7 +7653,7 @@
FieldEnd = ClassDecl->field_end();
HasConstCopyAssignment && Field != FieldEnd;
++Field) {
- QualType FieldType = Context.getBaseElementType((*Field)->getType());
+ QualType FieldType = Context.getBaseElementType(Field->getType());
if (CXXRecordDecl *FieldClassDecl = FieldType->getAsCXXRecordDecl()) {
HasConstCopyAssignment &=
(bool)LookupCopyingAssignment(FieldClassDecl, Qualifiers::Const,
@@ -7691,7 +7705,7 @@
FieldEnd = ClassDecl->field_end();
Field != FieldEnd;
++Field) {
- QualType FieldType = Context.getBaseElementType((*Field)->getType());
+ QualType FieldType = Context.getBaseElementType(Field->getType());
if (CXXRecordDecl *FieldClassDecl = FieldType->getAsCXXRecordDecl()) {
if (CXXMethodDecl *CopyAssign =
LookupCopyingAssignment(FieldClassDecl, ArgQuals, false, 0))
@@ -7917,7 +7931,7 @@
CXXScopeSpec SS; // Intentionally empty
LookupResult MemberLookup(*this, Field->getDeclName(), Loc,
LookupMemberName);
- MemberLookup.addDecl(*Field);
+ MemberLookup.addDecl(&*Field);
MemberLookup.resolveKind();
ExprResult From = BuildMemberReferenceExpr(OtherRef, OtherRefType,
Loc, /*IsArrow=*/false,
@@ -8119,7 +8133,7 @@
FieldEnd = ClassDecl->field_end();
Field != FieldEnd;
++Field) {
- QualType FieldType = Context.getBaseElementType((*Field)->getType());
+ QualType FieldType = Context.getBaseElementType(Field->getType());
if (CXXRecordDecl *FieldClassDecl = FieldType->getAsCXXRecordDecl()) {
if (CXXMethodDecl *MoveAssign = LookupMovingAssignment(FieldClassDecl,
false, 0))
@@ -8207,7 +8221,7 @@
for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
FieldEnd = ClassDecl->field_end();
Field != FieldEnd; ++Field) {
- if (!hasMoveOrIsTriviallyCopyable(S, (*Field)->getType(), IsConstructor))
+ if (!hasMoveOrIsTriviallyCopyable(S, Field->getType(), IsConstructor))
return false;
}
@@ -8452,7 +8466,7 @@
CXXScopeSpec SS; // Intentionally empty
LookupResult MemberLookup(*this, Field->getDeclName(), Loc,
LookupMemberName);
- MemberLookup.addDecl(*Field);
+ MemberLookup.addDecl(&*Field);
MemberLookup.resolveKind();
ExprResult From = BuildMemberReferenceExpr(OtherRef, OtherRefType,
Loc, /*IsArrow=*/false,
@@ -8668,7 +8682,7 @@
FieldEnd = ClassDecl->field_end();
HasConstCopyConstructor && Field != FieldEnd;
++Field) {
- QualType FieldType = Context.getBaseElementType((*Field)->getType());
+ QualType FieldType = Context.getBaseElementType(Field->getType());
if (CXXRecordDecl *FieldClassDecl = FieldType->getAsCXXRecordDecl()) {
HasConstCopyConstructor &=
(bool)LookupCopyingConstructor(FieldClassDecl, Qualifiers::Const);
@@ -8712,7 +8726,7 @@
FieldEnd = ClassDecl->field_end();
Field != FieldEnd;
++Field) {
- QualType FieldType = Context.getBaseElementType((*Field)->getType());
+ QualType FieldType = Context.getBaseElementType(Field->getType());
if (CXXRecordDecl *FieldClassDecl = FieldType->getAsCXXRecordDecl()) {
if (CXXConstructorDecl *CopyConstructor =
LookupCopyingConstructor(FieldClassDecl, Quals))
@@ -9892,7 +9906,7 @@
llvm::APSInt Cond;
if (VerifyIntegerConstantExpression(Converted.get(), &Cond,
- PDiag(diag::err_static_assert_expression_is_not_constant),
+ diag::err_static_assert_expression_is_not_constant,
/*AllowFold=*/false).isInvalid())
return 0;
@@ -10648,8 +10662,8 @@
if (const RecordType *RT = NewClassTy->getAs<RecordType>()) {
if (!RT->isBeingDefined() &&
RequireCompleteType(New->getLocation(), NewClassTy,
- PDiag(diag::err_covariant_return_incomplete)
- << New->getDeclName()))
+ diag::err_covariant_return_incomplete,
+ New->getDeclName()))
return true;
}
@@ -10937,7 +10951,7 @@
const CXXRecordDecl *RD) {
for (CXXRecordDecl::method_iterator i = RD->method_begin(),
e = RD->method_end(); i != e; ++i) {
- CXXMethodDecl *MD = *i;
+ CXXMethodDecl *MD = &*i;
// C++ [basic.def.odr]p2:
// [...] A virtual member function is used if it is not pure. [...]
@@ -11288,7 +11302,7 @@
if (!NoexceptExpr->isValueDependent())
NoexceptExpr = VerifyIntegerConstantExpression(NoexceptExpr, 0,
- PDiag(diag::err_noexcept_needs_constant_expression),
+ diag::err_noexcept_needs_constant_expression,
/*AllowFold*/ false).take();
EPI.NoexceptExpr = NoexceptExpr;
}
@@ -11296,70 +11310,6 @@
}
}
-void Sema::actOnDelayedExceptionSpecification(Decl *MethodD,
- ExceptionSpecificationType EST,
- SourceRange SpecificationRange,
- ArrayRef<ParsedType> DynamicExceptions,
- ArrayRef<SourceRange> DynamicExceptionRanges,
- Expr *NoexceptExpr) {
- if (!MethodD)
- return;
-
- // Dig out the method we're referring to.
- CXXMethodDecl *Method = 0;
- if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(MethodD))
- Method = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
- else
- Method = dyn_cast<CXXMethodDecl>(MethodD);
-
- if (!Method)
- return;
-
- // Dig out the prototype, looking through only parens. This should never fail.
- const FunctionProtoType *Proto
- = cast<FunctionProtoType>(Method->getType().IgnoreParens());
-
- // Check the exception specification.
- llvm::SmallVector<QualType, 4> Exceptions;
- FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo();
- checkExceptionSpecification(EST, DynamicExceptions, DynamicExceptionRanges,
- NoexceptExpr, Exceptions, EPI);
-
- // Rebuild the function type.
- QualType T = Context.getFunctionType(Proto->getResultType(),
- Proto->arg_type_begin(),
- Proto->getNumArgs(),
- EPI);
-
- // Rebuild any parens around the function type.
- for (const ParenType *PT = dyn_cast<ParenType>(Method->getType()); PT;
- PT = dyn_cast<ParenType>(PT->getInnerType()))
- T = Context.getParenType(T);
-
- if (TypeSourceInfo *TSInfo = Method->getTypeSourceInfo()) {
- // FIXME: When we get proper type location information for exceptions,
- // we'll also have to rebuild the TypeSourceInfo. For now, we just patch
- // up the TypeSourceInfo;
- assert(TypeLoc::getFullDataSizeForType(T)
- == TypeLoc::getFullDataSizeForType(Method->getType()) &&
- "TypeLoc size mismatch with delayed exception specification");
- TSInfo->overrideType(T);
- }
-
- Method->setType(T);
-
- if (Method->isStatic())
- checkThisInStaticMemberFunctionExceptionSpec(Method);
-
- if (Method->isVirtual()) {
- // Check overrides, which we previously had to delay.
- for (CXXMethodDecl::method_iterator O = Method->begin_overridden_methods(),
- OEnd = Method->end_overridden_methods();
- O != OEnd; ++O)
- CheckOverridingFunctionExceptionSpec(Method, *O);
- }
-}
-
/// IdentifyCUDATarget - Determine the CUDA compilation target for this function
Sema::CUDAFunctionTarget Sema::IdentifyCUDATarget(const FunctionDecl *D) {
// Implicitly declared functions (e.g. copy constructors) are
Modified: cfe/branches/tooling/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaDeclObjC.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaDeclObjC.cpp Tue May 8 03:47:31 2012
@@ -474,11 +474,11 @@
Diag(SuperLoc, diag::err_undef_superclass)
<< SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc);
else if (RequireCompleteType(SuperLoc,
- Context.getObjCInterfaceType(SuperClassDecl),
- PDiag(diag::err_forward_superclass)
- << SuperClassDecl->getDeclName()
- << ClassName
- << SourceRange(AtInterfaceLoc, ClassLoc))) {
+ Context.getObjCInterfaceType(SuperClassDecl),
+ diag::err_forward_superclass,
+ SuperClassDecl->getDeclName(),
+ ClassName,
+ SourceRange(AtInterfaceLoc, ClassLoc))) {
SuperClassDecl = 0;
}
}
@@ -694,7 +694,7 @@
llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap;
for (ObjCInterfaceDecl::method_iterator i = ID->meth_begin(),
e = ID->meth_end(); i != e; ++i) {
- ObjCMethodDecl *MD = *i;
+ ObjCMethodDecl *MD = &*i;
MethodMap[MD->getSelector()] = MD;
}
@@ -702,7 +702,7 @@
return;
for (ObjCCategoryDecl::method_iterator i = CAT->meth_begin(),
e = CAT->meth_end(); i != e; ++i) {
- ObjCMethodDecl *Method = *i;
+ ObjCMethodDecl *Method = &*i;
const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) {
Diag(Method->getLocation(), diag::err_duplicate_method_decl)
@@ -759,8 +759,8 @@
if (!IDecl
|| RequireCompleteType(ClassLoc, Context.getObjCInterfaceType(IDecl),
- PDiag(diag::err_category_forward_interface)
- << (CategoryName == 0))) {
+ diag::err_category_forward_interface,
+ CategoryName == 0)) {
// Create an invalid ObjCCategoryDecl to serve as context for
// the enclosing method declarations. We mark the decl invalid
// to make it clear that this isn't a valid AST.
@@ -1064,7 +1064,7 @@
IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end();
for (; numIvars > 0 && IVI != IVE; ++IVI) {
ObjCIvarDecl* ImplIvar = ivars[j++];
- ObjCIvarDecl* ClsIvar = *IVI;
+ ObjCIvarDecl* ClsIvar = &*IVI;
assert (ImplIvar && "missing implementation ivar");
assert (ClsIvar && "missing class ivar");
@@ -1094,7 +1094,7 @@
if (numIvars > 0)
Diag(ivars[j]->getLocation(), diag::err_inconsistant_ivar_count);
else if (IVI != IVE)
- Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count);
+ Diag(IVI->getLocation(), diag::err_inconsistant_ivar_count);
}
void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
@@ -2140,43 +2140,6 @@
return 0;
}
-/// CompareMethodParamsInBaseAndSuper - This routine compares methods with
-/// identical selector names in current and its super classes and issues
-/// a warning if any of their argument types are incompatible.
-void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl,
- ObjCMethodDecl *Method,
- bool IsInstance) {
- ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ClassDecl);
- if (ID == 0) return;
-
- while (ObjCInterfaceDecl *SD = ID->getSuperClass()) {
- ObjCMethodDecl *SuperMethodDecl =
- SD->lookupMethod(Method->getSelector(), IsInstance);
- if (SuperMethodDecl == 0) {
- ID = SD;
- continue;
- }
- ObjCMethodDecl::param_iterator ParamI = Method->param_begin(),
- E = Method->param_end();
- ObjCMethodDecl::param_iterator PrevI = SuperMethodDecl->param_begin();
- for (; ParamI != E; ++ParamI, ++PrevI) {
- // Number of parameters are the same and is guaranteed by selector match.
- assert(PrevI != SuperMethodDecl->param_end() && "Param mismatch");
- QualType T1 = Context.getCanonicalType((*ParamI)->getType());
- QualType T2 = Context.getCanonicalType((*PrevI)->getType());
- // If type of argument of method in this class does not match its
- // respective argument type in the super class method, issue warning;
- if (!Context.typesAreCompatible(T1, T2)) {
- Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
- << T1 << T2;
- Diag(SuperMethodDecl->getLocation(), diag::note_previous_declaration);
- return;
- }
- }
- ID = SD;
- }
-}
-
/// DiagnoseDuplicateIvars -
/// Check for duplicate ivars in the entire class at the start of
/// @implementation. This becomes necesssary because class extension can
@@ -2186,7 +2149,7 @@
ObjCInterfaceDecl *SID) {
for (ObjCInterfaceDecl::ivar_iterator IVI = ID->ivar_begin(),
IVE = ID->ivar_end(); IVI != IVE; ++IVI) {
- ObjCIvarDecl* Ivar = (*IVI);
+ ObjCIvarDecl* Ivar = &*IVI;
if (Ivar->isInvalidDecl())
continue;
if (IdentifierInfo *II = Ivar->getIdentifier()) {
@@ -2273,9 +2236,6 @@
InsMap[Method->getSelector()] = Method;
/// The following allows us to typecheck messages to "id".
AddInstanceMethodToGlobalPool(Method);
- // verify that the instance method conforms to the same definition of
- // parent methods if it shadows one.
- CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true);
}
} else {
/// Check for class method of the same name with incompatible types
@@ -2298,11 +2258,7 @@
Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
}
ClsMap[Method->getSelector()] = Method;
- /// The following allows us to typecheck messages to "Class".
AddFactoryMethodToGlobalPool(Method);
- // verify that the class method conforms to the same definition of
- // parent methods if it shadows one.
- CompareMethodParamsInBaseAndSuper(ClassDecl, Method, false);
}
}
}
@@ -2331,7 +2287,7 @@
for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
E = CDecl->prop_end();
I != E; ++I)
- ProcessPropertyDecl(*I, CDecl);
+ ProcessPropertyDecl(&*I, CDecl);
CDecl->setAtEndRange(AtEnd);
}
if (ObjCImplementationDecl *IC=dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
@@ -2347,7 +2303,7 @@
ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) {
for (ObjCContainerDecl::prop_iterator I = ClsExtDecl->prop_begin(),
E = ClsExtDecl->prop_end(); I != E; ++I) {
- ObjCPropertyDecl *Property = (*I);
+ ObjCPropertyDecl *Property = &*I;
// Skip over properties declared @dynamic
if (const ObjCPropertyImplDecl *PIDecl
= IC->FindPropertyImplDecl(Property->getIdentifier()))
@@ -2543,7 +2499,6 @@
public:
Sema &S;
ObjCMethodDecl *Method;
- llvm::SmallPtrSet<ObjCContainerDecl*, 128> Searched;
llvm::SmallPtrSet<ObjCMethodDecl*, 4> Overridden;
bool Recursive;
@@ -2572,8 +2527,12 @@
// Prevent the search from reaching this container again. This is
// important with categories, which override methods from the
// interface and each other.
- Searched.insert(container);
- searchFromContainer(container);
+ if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(container)) {
+ searchFromContainer(container);
+ searchFromContainer(Category->getClassInterface());
+ } else {
+ searchFromContainer(container);
+ }
}
typedef llvm::SmallPtrSet<ObjCMethodDecl*, 128>::iterator iterator;
@@ -2609,7 +2568,7 @@
void searchFrom(ObjCCategoryDecl *category) {
// A method in a category declaration overrides declarations from
// the main class and from protocols the category references.
- search(category->getClassInterface());
+ // The main class is handled in the constructor.
search(category->getReferencedProtocols());
}
@@ -2619,6 +2578,7 @@
// declaration.
if (ObjCCategoryDecl *category = impl->getCategoryDecl()) {
search(category);
+ search(category->getClassInterface());
// Otherwise it overrides declarations from the class.
} else {
@@ -2658,9 +2618,6 @@
}
void search(ObjCContainerDecl *container) {
- // Abort if we've already searched this container.
- if (!Searched.insert(container)) return;
-
// Check for a method in this container which matches this selector.
ObjCMethodDecl *meth = container->getMethod(Method->getSelector(),
Method->isInstanceMethod());
@@ -2889,6 +2846,27 @@
isa<ObjCImplementationDecl>(ObjCMethod->getDeclContext()))
CheckConflictingOverridingMethod(ObjCMethod, overridden,
isa<ObjCProtocolDecl>(overridden->getDeclContext()));
+
+ if (CurrentClass && overridden->getDeclContext() != CurrentClass &&
+ isa<ObjCInterfaceDecl>(overridden->getDeclContext())) {
+ ObjCMethodDecl::param_iterator ParamI = ObjCMethod->param_begin(),
+ E = ObjCMethod->param_end();
+ ObjCMethodDecl::param_iterator PrevI = overridden->param_begin();
+ for (; ParamI != E; ++ParamI, ++PrevI) {
+ // Number of parameters are the same and is guaranteed by selector match.
+ assert(PrevI != overridden->param_end() && "Param mismatch");
+ QualType T1 = Context.getCanonicalType((*ParamI)->getType());
+ QualType T2 = Context.getCanonicalType((*PrevI)->getType());
+ // If type of argument of method in this class does not match its
+ // respective argument type in the super class method, issue warning;
+ if (!Context.typesAreCompatible(T1, T2)) {
+ Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
+ << T1 << T2;
+ Diag(overridden->getLocation(), diag::note_previous_declaration);
+ break;
+ }
+ }
+ }
}
bool ARCError = false;
Modified: cfe/branches/tooling/lib/Sema/SemaExceptionSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaExceptionSpec.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaExceptionSpec.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaExceptionSpec.cpp Tue May 8 03:47:31 2012
@@ -51,7 +51,8 @@
// C++ 15.4p2: A type denoted in an exception-specification shall not denote
// an incomplete type.
if (RequireCompleteType(Range.getBegin(), T,
- PDiag(diag::err_incomplete_in_exception_spec) << /*direct*/0 << Range))
+ diag::err_incomplete_in_exception_spec,
+ /*direct*/0, Range))
return true;
// C++ 15.4p2: A type denoted in an exception-specification shall not denote
@@ -71,8 +72,9 @@
if (T->isRecordType() && T->getAs<RecordType>()->isBeingDefined())
return false;
- if (!T->isVoidType() && RequireCompleteType(Range.getBegin(), T,
- PDiag(diag::err_incomplete_in_exception_spec) << kind << Range))
+ if (!T->isVoidType() &&
+ RequireCompleteType(Range.getBegin(), T,
+ diag::err_incomplete_in_exception_spec, kind, Range))
return true;
return false;
Modified: cfe/branches/tooling/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaExpr.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaExpr.cpp Tue May 8 03:47:31 2012
@@ -560,7 +560,8 @@
// Complain about passing non-POD types through varargs. However, don't
// perform this check for incomplete types, which we can get here when we're
// in an unevaluated context.
- if (!E->getType()->isIncompleteType() && !E->getType().isPODType(Context)) {
+ if (!E->getType()->isIncompleteType() &&
+ !E->getType().isCXX98PODType(Context)) {
// C++0x [expr.call]p7:
// Passing a potentially-evaluated argument of class type (Clause 9)
// having a non-trivial copy constructor, a non-trivial move constructor,
@@ -2647,7 +2648,12 @@
diag::warn_cxx98_compat_longlong : diag::ext_longlong);
// Get the value in the widest-possible width.
- llvm::APInt ResultVal(Context.getTargetInfo().getIntMaxTWidth(), 0);
+ unsigned MaxWidth = Context.getTargetInfo().getIntMaxTWidth();
+ // The microsoft literal suffix extensions support 128-bit literals, which
+ // may be wider than [u]intmax_t.
+ if (Literal.isMicrosoftInteger && MaxWidth < 128)
+ MaxWidth = 128;
+ llvm::APInt ResultVal(MaxWidth, 0);
if (Literal.GetIntegerValue(ResultVal)) {
// If this value didn't fit into uintmax_t, warn and force to ull.
@@ -2695,7 +2701,7 @@
}
}
- // Finally, check long long if needed.
+ // Check long long if needed.
if (Ty.isNull()) {
unsigned LongLongSize = Context.getTargetInfo().getLongLongWidth();
@@ -2712,6 +2718,16 @@
Width = LongLongSize;
}
}
+
+ // If it doesn't fit in unsigned long long, and we're using Microsoft
+ // extensions, then its a 128-bit integer literal.
+ if (Ty.isNull() && Literal.isMicrosoftInteger) {
+ if (Literal.isUnsigned)
+ Ty = Context.UnsignedInt128Ty;
+ else
+ Ty = Context.Int128Ty;
+ Width = 128;
+ }
// If we still couldn't decide a type, we probably have something that
// does not fit in a signed long long, but has no U suffix.
@@ -2822,9 +2838,8 @@
return false;
if (RequireCompleteExprType(E,
- PDiag(diag::err_sizeof_alignof_incomplete_type)
- << ExprKind << E->getSourceRange(),
- std::make_pair(SourceLocation(), PDiag(0))))
+ diag::err_sizeof_alignof_incomplete_type,
+ ExprKind, E->getSourceRange()))
return true;
// Completeing the expression's type may have changed it.
@@ -2891,8 +2906,8 @@
return false;
if (RequireCompleteType(OpLoc, ExprType,
- PDiag(diag::err_sizeof_alignof_incomplete_type)
- << ExprKind << ExprRange))
+ diag::err_sizeof_alignof_incomplete_type,
+ ExprKind, ExprRange))
return true;
if (CheckObjCTraitOperandConstraints(*this, ExprType, OpLoc, ExprRange,
@@ -3230,8 +3245,7 @@
if (!ResultType.hasQualifiers()) VK = VK_RValue;
} else if (!ResultType->isDependentType() &&
RequireCompleteType(LLoc, ResultType,
- PDiag(diag::err_subscript_incomplete_type)
- << BaseExpr->getSourceRange()))
+ diag::err_subscript_incomplete_type, BaseExpr))
return ExprError();
// Diagnose bad cases where we step over interface counts.
@@ -3299,9 +3313,10 @@
if (Result.isInvalid())
return ExprError();
+ Expr *Arg = Result.takeAs<Expr>();
+ CheckImplicitConversions(Arg, Arg->getExprLoc());
// Build the default argument expression.
- return Owned(CXXDefaultArgExpr::Create(Context, CallLoc, Param,
- Result.takeAs<Expr>()));
+ return Owned(CXXDefaultArgExpr::Create(Context, CallLoc, Param, Arg));
}
// If the default expression creates temporaries, we need to
@@ -3448,8 +3463,7 @@
if (RequireCompleteType(Arg->getLocStart(),
ProtoArgType,
- PDiag(diag::err_call_incomplete_argument)
- << Arg->getSourceRange()))
+ diag::err_call_incomplete_argument, Arg))
return true;
// Pass the argument
@@ -3892,8 +3906,7 @@
if (RequireCompleteType(Arg->getLocStart(),
Arg->getType(),
- PDiag(diag::err_call_incomplete_argument)
- << Arg->getSourceRange()))
+ diag::err_call_incomplete_argument, Arg))
return ExprError();
TheCall->setArg(i, Arg);
@@ -3946,18 +3959,17 @@
if (literalType->isArrayType()) {
if (RequireCompleteType(LParenLoc, Context.getBaseElementType(literalType),
- PDiag(diag::err_illegal_decl_array_incomplete_type)
- << SourceRange(LParenLoc,
- LiteralExpr->getSourceRange().getEnd())))
+ diag::err_illegal_decl_array_incomplete_type,
+ SourceRange(LParenLoc,
+ LiteralExpr->getSourceRange().getEnd())))
return ExprError();
if (literalType->isVariableArrayType())
return ExprError(Diag(LParenLoc, diag::err_variable_object_no_init)
<< SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()));
} else if (!literalType->isDependentType() &&
RequireCompleteType(LParenLoc, literalType,
- PDiag(diag::err_typecheck_decl_incomplete_type)
- << SourceRange(LParenLoc,
- LiteralExpr->getSourceRange().getEnd())))
+ diag::err_typecheck_decl_incomplete_type,
+ SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd())))
return ExprError();
InitializedEntity Entity
@@ -5677,7 +5689,7 @@
if (RHSType->isPointerType())
if (RHSType->castAs<PointerType>()->getPointeeType()->isVoidType()) {
RHS = ImpCastExprToType(RHS.take(), it->getType(), CK_BitCast);
- InitField = *it;
+ InitField = &*it;
break;
}
@@ -5685,7 +5697,7 @@
Expr::NPC_ValueDependentIsNull)) {
RHS = ImpCastExprToType(RHS.take(), it->getType(),
CK_NullToPointer);
- InitField = *it;
+ InitField = &*it;
break;
}
}
@@ -5694,7 +5706,7 @@
if (CheckAssignmentConstraints(it->getType(), RHS, Kind)
== Compatible) {
RHS = ImpCastExprToType(RHS.take(), it->getType(), Kind);
- InitField = *it;
+ InitField = &*it;
break;
}
}
@@ -6042,8 +6054,8 @@
QualType PointeeTy = Operand->getType()->getPointeeType();
if (S.RequireCompleteType(
Loc, PointeeTy,
- S.PDiag(diag::err_typecheck_arithmetic_incomplete_type)
- << PointeeTy << Operand->getSourceRange()))
+ diag::err_typecheck_arithmetic_incomplete_type,
+ PointeeTy, Operand->getSourceRange()))
return true;
}
return false;
@@ -7271,8 +7283,7 @@
case Expr::MLV_IncompleteType:
case Expr::MLV_IncompleteVoidType:
return S.RequireCompleteType(Loc, E->getType(),
- S.PDiag(diag::err_typecheck_incomplete_type_not_modifiable_lvalue)
- << E->getSourceRange());
+ diag::err_typecheck_incomplete_type_not_modifiable_lvalue, E);
case Expr::MLV_DuplicateVectorComponents:
Diag = diag::err_typecheck_duplicate_vector_components_not_mlvalue;
break;
@@ -8669,8 +8680,7 @@
// with an incomplete type would be ill-formed.
if (!Dependent
&& RequireCompleteType(BuiltinLoc, ArgTy,
- PDiag(diag::err_offsetof_incomplete_type)
- << TypeRange))
+ diag::err_offsetof_incomplete_type, TypeRange))
return ExprError();
// offsetof with non-identifier designators (e.g. "offsetof(x, a.b[c])") are a
@@ -8743,10 +8753,18 @@
// The macro offsetof accepts a restricted set of type arguments in this
// International Standard. type shall be a POD structure or a POD union
// (clause 9).
+ // C++11 [support.types]p4:
+ // If type is not a standard-layout class (Clause 9), the results are
+ // undefined.
if (CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
- if (!CRD->isPOD() && !DidWarnAboutNonPOD &&
+ bool IsSafe = LangOpts.CPlusPlus0x? CRD->isStandardLayout() : CRD->isPOD();
+ unsigned DiagID =
+ LangOpts.CPlusPlus0x? diag::warn_offsetof_non_standardlayout_type
+ : diag::warn_offsetof_non_pod_type;
+
+ if (!IsSafe && !DidWarnAboutNonPOD &&
DiagRuntimeBehavior(BuiltinLoc, 0,
- PDiag(diag::warn_offsetof_non_pod_type)
+ PDiag(DiagID)
<< SourceRange(CompPtr[0].LocStart, OC.LocEnd)
<< CurrentType))
DidWarnAboutNonPOD = true;
@@ -8850,8 +8868,9 @@
} else {
// The conditional expression is required to be a constant expression.
llvm::APSInt condEval(32);
- ExprResult CondICE = VerifyIntegerConstantExpression(CondExpr, &condEval,
- PDiag(diag::err_typecheck_choose_expr_requires_constant), false);
+ ExprResult CondICE
+ = VerifyIntegerConstantExpression(CondExpr, &condEval,
+ diag::err_typecheck_choose_expr_requires_constant, false);
if (CondICE.isInvalid())
return ExprError();
CondExpr = CondICE.take();
@@ -9182,14 +9201,14 @@
if (!TInfo->getType()->isDependentType()) {
if (RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), TInfo->getType(),
- PDiag(diag::err_second_parameter_to_va_arg_incomplete)
- << TInfo->getTypeLoc().getSourceRange()))
+ diag::err_second_parameter_to_va_arg_incomplete,
+ TInfo->getTypeLoc()))
return ExprError();
if (RequireNonAbstractType(TInfo->getTypeLoc().getBeginLoc(),
- TInfo->getType(),
- PDiag(diag::err_second_parameter_to_va_arg_abstract)
- << TInfo->getTypeLoc().getSourceRange()))
+ TInfo->getType(),
+ diag::err_second_parameter_to_va_arg_abstract,
+ TInfo->getTypeLoc()))
return ExprError();
if (!TInfo->getType().isPODType(Context)) {
@@ -9434,15 +9453,44 @@
ExprResult Sema::VerifyIntegerConstantExpression(Expr *E,
llvm::APSInt *Result) {
- return VerifyIntegerConstantExpression(E, Result,
- PDiag(diag::err_expr_not_ice) << LangOpts.CPlusPlus);
+ class SimpleICEDiagnoser : public VerifyICEDiagnoser {
+ public:
+ virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) {
+ S.Diag(Loc, diag::err_expr_not_ice) << S.LangOpts.CPlusPlus << SR;
+ }
+ } Diagnoser;
+
+ return VerifyIntegerConstantExpression(E, Result, Diagnoser);
+}
+
+ExprResult Sema::VerifyIntegerConstantExpression(Expr *E,
+ llvm::APSInt *Result,
+ unsigned DiagID,
+ bool AllowFold) {
+ class IDDiagnoser : public VerifyICEDiagnoser {
+ unsigned DiagID;
+
+ public:
+ IDDiagnoser(unsigned DiagID)
+ : VerifyICEDiagnoser(DiagID == 0), DiagID(DiagID) { }
+
+ virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) {
+ S.Diag(Loc, DiagID) << SR;
+ }
+ } Diagnoser(DiagID);
+
+ return VerifyIntegerConstantExpression(E, Result, Diagnoser, AllowFold);
+}
+
+void Sema::VerifyICEDiagnoser::diagnoseFold(Sema &S, SourceLocation Loc,
+ SourceRange SR) {
+ S.Diag(Loc, diag::ext_expr_not_ice) << SR << S.LangOpts.CPlusPlus;
}
ExprResult
Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
- const PartialDiagnostic &NotIceDiag,
- bool AllowFold,
- const PartialDiagnostic &FoldDiag) {
+ VerifyICEDiagnoser &Diagnoser,
+ bool AllowFold) {
SourceLocation DiagLoc = E->getLocStart();
if (getLangOpts().CPlusPlus0x) {
@@ -9452,23 +9500,111 @@
// have a single non-explicit conversion function to an integral or
// unscoped enumeration type
ExprResult Converted;
- if (NotIceDiag.getDiagID()) {
- Converted = ConvertToIntegralOrEnumerationType(
- DiagLoc, E,
- PDiag(diag::err_ice_not_integral),
- PDiag(diag::err_ice_incomplete_type),
- PDiag(diag::err_ice_explicit_conversion),
- PDiag(diag::note_ice_conversion_here),
- PDiag(diag::err_ice_ambiguous_conversion),
- PDiag(diag::note_ice_conversion_here),
- PDiag(0),
- /*AllowScopedEnumerations*/ false);
+ if (!Diagnoser.Suppress) {
+ class CXX11ConvertDiagnoser : public ICEConvertDiagnoser {
+ public:
+ CXX11ConvertDiagnoser() : ICEConvertDiagnoser(false, true) { }
+
+ virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_ice_not_integral) << T;
+ }
+
+ virtual DiagnosticBuilder diagnoseIncomplete(Sema &S,
+ SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_ice_incomplete_type) << T;
+ }
+
+ virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S,
+ SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return S.Diag(Loc, diag::err_ice_explicit_conversion) << T << ConvTy;
+ }
+
+ virtual DiagnosticBuilder noteExplicitConv(Sema &S,
+ CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return S.Diag(Conv->getLocation(), diag::note_ice_conversion_here)
+ << ConvTy->isEnumeralType() << ConvTy;
+ }
+
+ virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_ice_ambiguous_conversion) << T;
+ }
+
+ virtual DiagnosticBuilder noteAmbiguous(Sema &S,
+ CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return S.Diag(Conv->getLocation(), diag::note_ice_conversion_here)
+ << ConvTy->isEnumeralType() << ConvTy;
+ }
+
+ virtual DiagnosticBuilder diagnoseConversion(Sema &S,
+ SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return DiagnosticBuilder::getEmpty();
+ }
+ } ConvertDiagnoser;
+
+ Converted = ConvertToIntegralOrEnumerationType(DiagLoc, E,
+ ConvertDiagnoser,
+ /*AllowScopedEnumerations*/ false);
} else {
// The caller wants to silently enquire whether this is an ICE. Don't
// produce any diagnostics if it isn't.
- Converted = ConvertToIntegralOrEnumerationType(
- DiagLoc, E, PDiag(), PDiag(), PDiag(), PDiag(),
- PDiag(), PDiag(), PDiag(), false);
+ class SilentICEConvertDiagnoser : public ICEConvertDiagnoser {
+ public:
+ SilentICEConvertDiagnoser() : ICEConvertDiagnoser(true, true) { }
+
+ virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return DiagnosticBuilder::getEmpty();
+ }
+
+ virtual DiagnosticBuilder diagnoseIncomplete(Sema &S,
+ SourceLocation Loc,
+ QualType T) {
+ return DiagnosticBuilder::getEmpty();
+ }
+
+ virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S,
+ SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return DiagnosticBuilder::getEmpty();
+ }
+
+ virtual DiagnosticBuilder noteExplicitConv(Sema &S,
+ CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return DiagnosticBuilder::getEmpty();
+ }
+
+ virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return DiagnosticBuilder::getEmpty();
+ }
+
+ virtual DiagnosticBuilder noteAmbiguous(Sema &S,
+ CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return DiagnosticBuilder::getEmpty();
+ }
+
+ virtual DiagnosticBuilder diagnoseConversion(Sema &S,
+ SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return DiagnosticBuilder::getEmpty();
+ }
+ } ConvertDiagnoser;
+
+ Converted = ConvertToIntegralOrEnumerationType(DiagLoc, E,
+ ConvertDiagnoser, false);
}
if (Converted.isInvalid())
return Converted;
@@ -9477,8 +9613,8 @@
return ExprError();
} else if (!E->getType()->isIntegralOrUnscopedEnumerationType()) {
// An ICE must be of integral or unscoped enumeration type.
- if (NotIceDiag.getDiagID())
- Diag(DiagLoc, NotIceDiag) << E->getSourceRange();
+ if (!Diagnoser.Suppress)
+ Diagnoser.diagnoseNotICE(*this, DiagLoc, E->getSourceRange());
return ExprError();
}
@@ -9518,8 +9654,8 @@
}
if (!Folded || !AllowFold) {
- if (NotIceDiag.getDiagID()) {
- Diag(DiagLoc, NotIceDiag) << E->getSourceRange();
+ if (!Diagnoser.Suppress) {
+ Diagnoser.diagnoseNotICE(*this, DiagLoc, E->getSourceRange());
for (unsigned I = 0, N = Notes.size(); I != N; ++I)
Diag(Notes[I].first, Notes[I].second);
}
@@ -9527,11 +9663,7 @@
return ExprError();
}
- if (FoldDiag.getDiagID())
- Diag(DiagLoc, FoldDiag) << E->getSourceRange();
- else
- Diag(DiagLoc, diag::ext_expr_not_ice)
- << E->getSourceRange() << LangOpts.CPlusPlus;
+ Diagnoser.diagnoseFold(*this, DiagLoc, E->getSourceRange());
for (unsigned I = 0, N = Notes.size(); I != N; ++I)
Diag(Notes[I].first, Notes[I].second);
@@ -10645,18 +10777,30 @@
return false;
}
- PartialDiagnostic Note =
- FD ? PDiag(diag::note_function_with_incomplete_return_type_declared_here)
- << FD->getDeclName() : PDiag();
- SourceLocation NoteLoc = FD ? FD->getLocation() : SourceLocation();
-
- if (RequireCompleteType(Loc, ReturnType,
- FD ?
- PDiag(diag::err_call_function_incomplete_return)
- << CE->getSourceRange() << FD->getDeclName() :
- PDiag(diag::err_call_incomplete_return)
- << CE->getSourceRange(),
- std::make_pair(NoteLoc, Note)))
+ class CallReturnIncompleteDiagnoser : public TypeDiagnoser {
+ FunctionDecl *FD;
+ CallExpr *CE;
+
+ public:
+ CallReturnIncompleteDiagnoser(FunctionDecl *FD, CallExpr *CE)
+ : FD(FD), CE(CE) { }
+
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ if (!FD) {
+ S.Diag(Loc, diag::err_call_incomplete_return)
+ << T << CE->getSourceRange();
+ return;
+ }
+
+ S.Diag(Loc, diag::err_call_function_incomplete_return)
+ << CE->getSourceRange() << FD->getDeclName() << T;
+ S.Diag(FD->getLocation(),
+ diag::note_function_with_incomplete_return_type_declared_here)
+ << FD->getDeclName();
+ }
+ } Diagnoser(FD, CE);
+
+ if (RequireCompleteType(Loc, ReturnType, Diagnoser))
return true;
return false;
Modified: cfe/branches/tooling/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaExprCXX.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaExprCXX.cpp Tue May 8 03:47:31 2012
@@ -584,14 +584,13 @@
}
if (!isPointer || !Ty->isVoidType()) {
if (RequireCompleteType(ThrowLoc, Ty,
- PDiag(isPointer ? diag::err_throw_incomplete_ptr
- : diag::err_throw_incomplete)
- << E->getSourceRange()))
+ isPointer? diag::err_throw_incomplete_ptr
+ : diag::err_throw_incomplete,
+ E->getSourceRange()))
return ExprError();
if (RequireNonAbstractType(ThrowLoc, E->getType(),
- PDiag(diag::err_throw_abstract_type)
- << E->getSourceRange()))
+ diag::err_throw_abstract_type, E))
return ExprError();
}
@@ -693,10 +692,6 @@
}
void Sema::CheckCXXThisCapture(SourceLocation Loc, bool Explicit) {
- if (getLangOpts().CPlusPlus0x &&
- !dyn_cast_or_null<CXXMethodDecl>(getFunctionLevelDeclContext()))
- Diag(Loc, diag::warn_cxx98_compat_this_outside_method);
-
// We don't need to capture this in an unevaluated context.
if (ExprEvalContexts.back().Context == Unevaluated && !Explicit)
return;
@@ -843,8 +838,7 @@
if (!Ty->isVoidType() &&
RequireCompleteType(TyBeginLoc, ElemTy,
- PDiag(diag::err_invalid_incomplete_type_use)
- << FullRange))
+ diag::err_invalid_incomplete_type_use, FullRange))
return ExprError();
if (RequireNonAbstractType(TyBeginLoc, Ty,
@@ -988,8 +982,10 @@
DeclaratorChunk::ArrayTypeInfo &Array = D.getTypeObject(I).Arr;
if (Expr *NumElts = (Expr *)Array.NumElts) {
if (!NumElts->isTypeDependent() && !NumElts->isValueDependent()) {
- Array.NumElts = VerifyIntegerConstantExpression(NumElts, 0,
- PDiag(diag::err_new_array_nonconst)).take();
+ Array.NumElts
+ = VerifyIntegerConstantExpression(NumElts, 0,
+ diag::err_new_array_nonconst)
+ .take();
if (!Array.NumElts)
return ExprError();
}
@@ -1154,19 +1150,64 @@
// enumeration type, or a class type for which a single non-explicit
// conversion function to integral or unscoped enumeration type exists.
if (ArraySize && !ArraySize->isTypeDependent()) {
- ExprResult ConvertedSize = ConvertToIntegralOrEnumerationType(
- StartLoc, ArraySize,
- PDiag(diag::err_array_size_not_integral) << getLangOpts().CPlusPlus0x,
- PDiag(diag::err_array_size_incomplete_type)
- << ArraySize->getSourceRange(),
- PDiag(diag::err_array_size_explicit_conversion),
- PDiag(diag::note_array_size_conversion),
- PDiag(diag::err_array_size_ambiguous_conversion),
- PDiag(diag::note_array_size_conversion),
- PDiag(getLangOpts().CPlusPlus0x ?
- diag::warn_cxx98_compat_array_size_conversion :
- diag::ext_array_size_conversion),
- /*AllowScopedEnumerations*/ false);
+ class SizeConvertDiagnoser : public ICEConvertDiagnoser {
+ Expr *ArraySize;
+
+ public:
+ SizeConvertDiagnoser(Expr *ArraySize)
+ : ICEConvertDiagnoser(false, false), ArraySize(ArraySize) { }
+
+ virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_array_size_not_integral)
+ << S.getLangOpts().CPlusPlus0x << T;
+ }
+
+ virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_array_size_incomplete_type)
+ << T << ArraySize->getSourceRange();
+ }
+
+ virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S,
+ SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return S.Diag(Loc, diag::err_array_size_explicit_conversion) << T << ConvTy;
+ }
+
+ virtual DiagnosticBuilder noteExplicitConv(Sema &S,
+ CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return S.Diag(Conv->getLocation(), diag::note_array_size_conversion)
+ << ConvTy->isEnumeralType() << ConvTy;
+ }
+
+ virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_array_size_ambiguous_conversion) << T;
+ }
+
+ virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return S.Diag(Conv->getLocation(), diag::note_array_size_conversion)
+ << ConvTy->isEnumeralType() << ConvTy;
+ }
+
+ virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return S.Diag(Loc,
+ S.getLangOpts().CPlusPlus0x
+ ? diag::warn_cxx98_compat_array_size_conversion
+ : diag::ext_array_size_conversion)
+ << T << ConvTy->isEnumeralType() << ConvTy;
+ }
+ } SizeDiagnoser(ArraySize);
+
+ ExprResult ConvertedSize
+ = ConvertToIntegralOrEnumerationType(StartLoc, ArraySize, SizeDiagnoser,
+ /*AllowScopedEnumerations*/ false);
if (ConvertedSize.isInvalid())
return ExprError();
@@ -1405,9 +1446,7 @@
return Diag(Loc, diag::err_bad_new_type)
<< AllocType << 1 << R;
else if (!AllocType->isDependentType() &&
- RequireCompleteType(Loc, AllocType,
- PDiag(diag::err_new_incomplete_type)
- << R))
+ RequireCompleteType(Loc, AllocType, diag::err_new_incomplete_type,R))
return true;
else if (RequireNonAbstractType(Loc, AllocType,
diag::err_allocation_of_abstract_type))
@@ -2018,7 +2057,7 @@
if (const RecordType *Record = Type->getAs<RecordType>()) {
if (RequireCompleteType(StartLoc, Type,
- PDiag(diag::err_delete_incomplete_class_type)))
+ diag::err_delete_incomplete_class_type))
return ExprError();
SmallVector<CXXConversionDecl*, 4> ObjectPtrConversions;
@@ -2088,8 +2127,7 @@
<< Type << Ex.get()->getSourceRange());
} else if (!Pointee->isDependentType()) {
if (!RequireCompleteType(StartLoc, Pointee,
- PDiag(diag::warn_delete_incomplete)
- << Ex.get()->getSourceRange())) {
+ diag::warn_delete_incomplete, Ex.get())) {
if (const RecordType *RT = PointeeElem->getAs<RecordType>())
PointeeRD = cast<CXXRecordDecl>(RT->getDecl());
}
@@ -3619,7 +3657,7 @@
llvm::APSInt Value;
uint64_t Dim;
if (Self.VerifyIntegerConstantExpression(DimExpr, &Value,
- Self.PDiag(diag::err_dimension_expr_not_constant_integer),
+ diag::err_dimension_expr_not_constant_integer,
false).isInvalid())
return 0;
if (Value.isSigned() && Value.isNegative()) {
@@ -3771,8 +3809,8 @@
if (!Context.hasSameUnqualifiedType(Class, LHSType)) {
// If we want to check the hierarchy, we need a complete type.
- if (RequireCompleteType(Loc, LHSType, PDiag(diag::err_bad_memptr_lhs)
- << OpSpelling << (int)isIndirect)) {
+ if (RequireCompleteType(Loc, LHSType, diag::err_bad_memptr_lhs,
+ OpSpelling, (int)isIndirect)) {
return QualType();
}
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
@@ -4837,8 +4875,7 @@
// the member function body.
if (!BaseType->isDependentType() &&
!isThisOutsideMemberFunctionBody(BaseType) &&
- RequireCompleteType(OpLoc, BaseType,
- PDiag(diag::err_incomplete_member_access)))
+ RequireCompleteType(OpLoc, BaseType, diag::err_incomplete_member_access))
return ExprError();
// C++ [basic.lookup.classref]p2:
Modified: cfe/branches/tooling/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaExprMember.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaExprMember.cpp Tue May 8 03:47:31 2012
@@ -548,8 +548,8 @@
RecordDecl *RDecl = RTy->getDecl();
if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) &&
SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0),
- SemaRef.PDiag(diag::err_typecheck_incomplete_tag)
- << BaseRange))
+ diag::err_typecheck_incomplete_tag,
+ BaseRange))
return true;
if (HasTemplateArgs) {
@@ -839,7 +839,7 @@
if (ExtraArgs) {
ExprResult RetryExpr;
if (!IsArrow && BaseExpr) {
- SFINAETrap Trap(*this);
+ SFINAETrap Trap(*this, true);
ParsedType ObjectType;
bool MayBePseudoDestructor = false;
RetryExpr = ActOnStartCXXMemberReference(getCurScope(), BaseExpr,
@@ -1150,9 +1150,8 @@
goto fail;
}
- if (RequireCompleteType(OpLoc, BaseType,
- PDiag(diag::err_typecheck_incomplete_tag)
- << BaseExpr.get()->getSourceRange()))
+ if (RequireCompleteType(OpLoc, BaseType, diag::err_typecheck_incomplete_tag,
+ BaseExpr.get()))
return ExprError();
ObjCInterfaceDecl *ClassDeclared = 0;
Modified: cfe/branches/tooling/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaExprObjC.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaExprObjC.cpp Tue May 8 03:47:31 2012
@@ -237,9 +237,6 @@
/// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the
/// numeric literal expression. Type of the expression will be "NSNumber *".
ExprResult Sema::BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number) {
- // compute the effective range of the literal, including the leading '@'.
- SourceRange SR(AtLoc, Number->getSourceRange().getEnd());
-
// Determine the type of the literal.
QualType NumberType = Number->getType();
if (CharacterLiteral *Char = dyn_cast<CharacterLiteral>(Number)) {
@@ -266,21 +263,27 @@
// Look for the appropriate method within NSNumber.
// Construct the literal.
+ SourceRange NR(Number->getSourceRange());
ObjCMethodDecl *Method = getNSNumberFactoryMethod(*this, AtLoc, NumberType,
- true, Number->getSourceRange());
+ true, NR);
if (!Method)
return ExprError();
// Convert the number to the type that the parameter expects.
- QualType ArgType = Method->param_begin()[0]->getType();
- ExprResult ConvertedNumber = PerformImplicitConversion(Number, ArgType,
- AA_Sending);
+ ParmVarDecl *ParamDecl = Method->param_begin()[0];
+ InitializedEntity Entity = InitializedEntity::InitializeParameter(Context,
+ ParamDecl);
+ ExprResult ConvertedNumber = PerformCopyInitialization(Entity,
+ SourceLocation(),
+ Owned(Number));
if (ConvertedNumber.isInvalid())
return ExprError();
Number = ConvertedNumber.get();
+ // Use the effective source range of the literal, including the leading '@'.
return MaybeBindToTemporary(
- new (Context) ObjCBoxedExpr(Number, NSNumberPointer, Method, SR));
+ new (Context) ObjCBoxedExpr(Number, NSNumberPointer, Method,
+ SourceRange(AtLoc, NR.getEnd())));
}
ExprResult Sema::ActOnObjCBoolLiteral(SourceLocation AtLoc,
@@ -408,7 +411,7 @@
return ExprError();
}
ValueExpr = RValue.get();
- QualType ValueType(ValueExpr->getType().getCanonicalType());
+ QualType ValueType(ValueExpr->getType());
if (const PointerType *PT = ValueType->getAs<PointerType>()) {
QualType PointeeType = PT->getPointeeType();
if (Context.hasSameUnqualifiedType(PointeeType, Context.CharTy)) {
@@ -475,7 +478,7 @@
BoxingMethod = StringWithUTF8StringMethod;
BoxedType = NSStringPointer;
}
- } else if (isa<BuiltinType>(ValueType)) {
+ } else if (ValueType->isBuiltinType()) {
// The other types we support are numeric, char and BOOL/bool. We could also
// provide limited support for structure types, such as NSRange, NSRect, and
// NSSize. See NSValue (NSValueGeometryExtensions) in <Foundation/NSGeometry.h>
@@ -519,9 +522,12 @@
}
// Convert the expression to the type that the parameter requires.
- QualType ArgType = BoxingMethod->param_begin()[0]->getType();
- ExprResult ConvertedValueExpr = PerformImplicitConversion(ValueExpr, ArgType,
- AA_Sending);
+ ParmVarDecl *ParamDecl = BoxingMethod->param_begin()[0];
+ InitializedEntity Entity = InitializedEntity::InitializeParameter(Context,
+ ParamDecl);
+ ExprResult ConvertedValueExpr = PerformCopyInitialization(Entity,
+ SourceLocation(),
+ Owned(ValueExpr));
if (ConvertedValueExpr.isInvalid())
return ExprError();
ValueExpr = ConvertedValueExpr.get();
@@ -904,8 +910,8 @@
if (!EncodedType->getAsArrayTypeUnsafe() && //// Incomplete array is handled.
!EncodedType->isVoidType()) // void is handled too.
if (RequireCompleteType(AtLoc, EncodedType,
- PDiag(diag::err_incomplete_type_objc_at_encode)
- << EncodedTypeInfo->getTypeLoc().getSourceRange()))
+ diag::err_incomplete_type_objc_at_encode,
+ EncodedTypeInfo->getTypeLoc()))
return ExprError();
std::string Str;
@@ -1170,8 +1176,7 @@
if (RequireCompleteType(argExpr->getSourceRange().getBegin(),
param->getType(),
- PDiag(diag::err_call_incomplete_argument)
- << argExpr->getSourceRange()))
+ diag::err_call_incomplete_argument, argExpr))
return true;
InitializedEntity Entity = InitializedEntity::InitializeParameter(Context,
@@ -1389,8 +1394,8 @@
SourceRange BaseRange = Super? SourceRange(SuperLoc)
: BaseExpr->getSourceRange();
if (RequireCompleteType(MemberLoc, OPT->getPointeeType(),
- PDiag(diag::err_property_not_found_forward_class)
- << MemberName << BaseRange))
+ diag::err_property_not_found_forward_class,
+ MemberName, BaseRange))
return ExprError();
// Search for a declared property first.
@@ -1518,8 +1523,8 @@
if (const ObjCObjectPointerType * OBJPT =
T->getAsObjCInterfacePointerType()) {
if (RequireCompleteType(MemberLoc, OBJPT->getPointeeType(),
- PDiag(diag::err_property_not_as_forward_class)
- << MemberName << BaseExpr->getSourceRange()))
+ diag::err_property_not_as_forward_class,
+ MemberName, BaseExpr))
return ExprError();
}
Diag(MemberLoc,
@@ -1952,11 +1957,11 @@
SourceRange TypeRange
= SuperLoc.isValid()? SourceRange(SuperLoc)
: ReceiverTypeInfo->getTypeLoc().getSourceRange();
- if (RequireCompleteType(Loc, Context.getObjCInterfaceType(Class),
+ if (RequireCompleteType(Loc, Context.getObjCInterfaceType(Class),
(getLangOpts().ObjCAutoRefCount
- ? PDiag(diag::err_arc_receiver_forward_class)
- : PDiag(diag::warn_receiver_forward_class))
- << TypeRange)) {
+ ? diag::err_arc_receiver_forward_class
+ : diag::warn_receiver_forward_class),
+ TypeRange)) {
// A forward class used in messaging is treated as a 'Class'
Method = LookupFactoryMethodInGlobalPool(Sel,
SourceRange(LBracLoc, RBracLoc));
@@ -2215,12 +2220,10 @@
const ObjCInterfaceDecl *forwardClass = 0;
if (RequireCompleteType(Loc, OCIType->getPointeeType(),
getLangOpts().ObjCAutoRefCount
- ? PDiag(diag::err_arc_receiver_forward_instance)
- << (Receiver ? Receiver->getSourceRange()
- : SourceRange(SuperLoc))
- : PDiag(diag::warn_receiver_forward_instance)
- << (Receiver ? Receiver->getSourceRange()
- : SourceRange(SuperLoc)))) {
+ ? diag::err_arc_receiver_forward_instance
+ : diag::warn_receiver_forward_instance,
+ Receiver? Receiver->getSourceRange()
+ : SourceRange(SuperLoc))) {
if (getLangOpts().ObjCAutoRefCount)
return ExprError();
Modified: cfe/branches/tooling/lib/Sema/SemaFixItUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaFixItUtils.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaFixItUtils.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaFixItUtils.cpp Tue May 8 03:47:31 2012
@@ -163,42 +163,54 @@
return S.PP.getMacroInfo(&S.getASTContext().Idents.get(Name));
}
-const char *Sema::getFixItZeroInitializerForType(QualType T) const {
+static std::string getScalarZeroExpressionForType(const Type& T, const Sema& S) {
+ assert(T.isScalarType() && "use scalar types only");
+ // Suggest "0" for non-enumeration scalar types, unless we can find a
+ // better initializer.
+ if (T.isEnumeralType())
+ return std::string();
+ if ((T.isObjCObjectPointerType() || T.isBlockPointerType()) &&
+ isMacroDefined(S, "nil"))
+ return "nil";
+ if (T.isRealFloatingType())
+ return "0.0";
+ if (T.isBooleanType() && S.LangOpts.CPlusPlus)
+ return "false";
+ if (T.isPointerType() || T.isMemberPointerType()) {
+ if (S.LangOpts.CPlusPlus0x)
+ return "nullptr";
+ if (isMacroDefined(S, "NULL"))
+ return "NULL";
+ }
+ if (T.isCharType())
+ return "'\\0'";
+ if (T.isWideCharType())
+ return "L'\\0'";
+ if (T.isChar16Type())
+ return "u'\\0'";
+ if (T.isChar32Type())
+ return "U'\\0'";
+ return "0";
+}
+
+std::string Sema::getFixItZeroInitializerForType(QualType T) const {
if (T->isScalarType()) {
- // Suggest " = 0" for non-enumeration scalar types, unless we can find a
- // better initializer.
- if (T->isEnumeralType())
- return 0;
- if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) &&
- isMacroDefined(*this, "nil"))
- return " = nil";
- if (T->isRealFloatingType())
- return " = 0.0";
- if (T->isBooleanType() && LangOpts.CPlusPlus)
- return " = false";
- if (T->isPointerType() || T->isMemberPointerType()) {
- if (LangOpts.CPlusPlus0x)
- return " = nullptr";
- else if (isMacroDefined(*this, "NULL"))
- return " = NULL";
- }
- if (T->isCharType())
- return " = '\\0'";
- if (T->isWideCharType())
- return " = L'\\0'";
- if (T->isChar16Type())
- return " = u'\\0'";
- if (T->isChar32Type())
- return " = U'\\0'";
- return " = 0";
+ std::string s = getScalarZeroExpressionForType(*T, *this);
+ if (!s.empty())
+ s = " = " + s;
+ return s;
}
const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
if (!RD || !RD->hasDefinition())
- return 0;
+ return std::string();
if (LangOpts.CPlusPlus0x && !RD->hasUserProvidedDefaultConstructor())
return "{}";
if (RD->isAggregate())
return " = {}";
- return 0;
+ return std::string();
+}
+
+std::string Sema::getFixItZeroLiteralForType(QualType T) const {
+ return getScalarZeroExpressionForType(*T, *this);
}
Modified: cfe/branches/tooling/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaInit.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaInit.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaInit.cpp Tue May 8 03:47:31 2012
@@ -375,7 +375,7 @@
if (hadError)
return;
- FillInValueInitForField(Init, *Field, Entity, ILE, RequiresSecondPass);
+ FillInValueInitForField(Init, &*Field, Entity, ILE, RequiresSecondPass);
if (hadError)
return;
@@ -1336,9 +1336,9 @@
if (Field->getDeclName()) {
if (VerifyOnly)
CheckValueInitializable(
- InitializedEntity::InitializeMember(*Field, &Entity));
+ InitializedEntity::InitializeMember(&*Field, &Entity));
else
- StructuredList->setInitializedFieldInUnion(*Field);
+ StructuredList->setInitializedFieldInUnion(&*Field);
break;
}
}
@@ -1401,9 +1401,9 @@
// Make sure we can use this declaration.
bool InvalidUse;
if (VerifyOnly)
- InvalidUse = !SemaRef.CanUseDecl(*Field);
+ InvalidUse = !SemaRef.CanUseDecl(&*Field);
else
- InvalidUse = SemaRef.DiagnoseUseOfDecl(*Field,
+ InvalidUse = SemaRef.DiagnoseUseOfDecl(&*Field,
IList->getInit(Index)->getLocStart());
if (InvalidUse) {
++Index;
@@ -1413,14 +1413,14 @@
}
InitializedEntity MemberEntity =
- InitializedEntity::InitializeMember(*Field, &Entity);
+ InitializedEntity::InitializeMember(&*Field, &Entity);
CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
StructuredList, StructuredIndex);
InitializedSomething = true;
if (DeclType->isUnionType() && !VerifyOnly) {
// Initialize the first field within the union.
- StructuredList->setInitializedFieldInUnion(*Field);
+ StructuredList->setInitializedFieldInUnion(&*Field);
}
++Field;
@@ -1449,7 +1449,7 @@
for (; Field != FieldEnd && !hadError; ++Field) {
if (!Field->isUnnamedBitfield())
CheckValueInitializable(
- InitializedEntity::InitializeMember(*Field, &Entity));
+ InitializedEntity::InitializeMember(&*Field, &Entity));
}
}
@@ -1457,7 +1457,7 @@
Index >= IList->getNumInits())
return;
- if (CheckFlexibleArrayInit(Entity, IList->getInit(Index), *Field,
+ if (CheckFlexibleArrayInit(Entity, IList->getInit(Index), &*Field,
TopLevelObject)) {
hadError = true;
++Index;
@@ -1465,7 +1465,7 @@
}
InitializedEntity MemberEntity =
- InitializedEntity::InitializeMember(*Field, &Entity);
+ InitializedEntity::InitializeMember(&*Field, &Entity);
if (isa<InitListExpr>(IList->getInit(Index)))
CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
@@ -1679,7 +1679,7 @@
// IndirectFieldDecl that follow for the designated initializer.
if (!KnownField && Field->isAnonymousStructOrUnion()) {
if (IndirectFieldDecl *IF =
- FindIndirectFieldDesignator(*Field, FieldName)) {
+ FindIndirectFieldDesignator(&*Field, FieldName)) {
// In verify mode, don't modify the original.
if (VerifyOnly)
DIE = CloneDesignatedInitExpr(SemaRef, DIE);
@@ -1688,7 +1688,7 @@
break;
}
}
- if (KnownField && KnownField == *Field)
+ if (KnownField && KnownField == &*Field)
break;
if (FieldName && FieldName == Field->getIdentifier())
break;
@@ -1757,7 +1757,7 @@
if (Field->isUnnamedBitfield())
continue;
- if (ReplacementField == *Field ||
+ if (ReplacementField == &*Field ||
Field->getIdentifier() == ReplacementField->getIdentifier())
break;
@@ -1771,15 +1771,15 @@
if (RT->getDecl()->isUnion()) {
FieldIndex = 0;
if (!VerifyOnly)
- StructuredList->setInitializedFieldInUnion(*Field);
+ StructuredList->setInitializedFieldInUnion(&*Field);
}
// Make sure we can use this declaration.
bool InvalidUse;
if (VerifyOnly)
- InvalidUse = !SemaRef.CanUseDecl(*Field);
+ InvalidUse = !SemaRef.CanUseDecl(&*Field);
else
- InvalidUse = SemaRef.DiagnoseUseOfDecl(*Field, D->getFieldLoc());
+ InvalidUse = SemaRef.DiagnoseUseOfDecl(&*Field, D->getFieldLoc());
if (InvalidUse) {
++Index;
return true;
@@ -1787,7 +1787,7 @@
if (!VerifyOnly) {
// Update the designator with the field declaration.
- D->setField(*Field);
+ D->setField(&*Field);
// Make sure that our non-designated initializer list has space
// for a subobject corresponding to this field.
@@ -1809,7 +1809,7 @@
<< SourceRange(NextD->getStartLocation(),
DIE->getSourceRange().getEnd());
SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
- << *Field;
+ << &*Field;
}
Invalid = true;
}
@@ -1822,13 +1822,13 @@
diag::err_flexible_array_init_needs_braces)
<< DIE->getInit()->getSourceRange();
SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
- << *Field;
+ << &*Field;
}
Invalid = true;
}
// Check GNU flexible array initializer.
- if (!Invalid && CheckFlexibleArrayInit(Entity, DIE->getInit(), *Field,
+ if (!Invalid && CheckFlexibleArrayInit(Entity, DIE->getInit(), &*Field,
TopLevelObject))
Invalid = true;
@@ -1844,7 +1844,7 @@
IList->setInit(Index, DIE->getInit());
InitializedEntity MemberEntity =
- InitializedEntity::InitializeMember(*Field, &Entity);
+ InitializedEntity::InitializeMember(&*Field, &Entity);
CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
StructuredList, newStructuredIndex);
@@ -1859,11 +1859,11 @@
}
} else {
// Recurse to check later designated subobjects.
- QualType FieldType = (*Field)->getType();
+ QualType FieldType = Field->getType();
unsigned newStructuredIndex = FieldIndex;
InitializedEntity MemberEntity =
- InitializedEntity::InitializeMember(*Field, &Entity);
+ InitializedEntity::InitializeMember(&*Field, &Entity);
if (CheckDesignatedInitializer(MemberEntity, IList, DIE, DesigIdx + 1,
FieldType, 0, 0, Index,
StructuredList, newStructuredIndex,
@@ -3108,7 +3108,7 @@
return;
}
if (DestType->isRecordType()) {
- if (S.RequireCompleteType(InitList->getLocStart(), DestType, S.PDiag())) {
+ if (S.RequireCompleteType(InitList->getLocStart(), DestType, 0)) {
Sequence.setIncompleteTypeFailure(DestType);
return;
}
@@ -3642,11 +3642,10 @@
// user-provided or deleted default constructor, then the object is
// zero-initialized and, if T has a non-trivial default constructor,
// default-initialized;
- if ((ClassDecl->getTagKind() == TTK_Class ||
- ClassDecl->getTagKind() == TTK_Struct)) {
- Sequence.AddZeroInitializationStep(Entity.getType());
- return TryConstructorInitialization(S, Entity, Kind, 0, 0, T, Sequence);
- }
+ // FIXME: The 'non-union' here is a defect (not yet assigned an issue
+ // number). Update the quotation when the defect is resolved.
+ Sequence.AddZeroInitializationStep(Entity.getType());
+ return TryConstructorInitialization(S, Entity, Kind, 0, 0, T, Sequence);
}
}
@@ -4452,7 +4451,7 @@
SourceLocation Loc = getInitializationLoc(Entity, CurInit.get());
// Make sure that the type we are copying is complete.
- if (S.RequireCompleteType(Loc, T, S.PDiag(diag::err_temp_copy_incomplete)))
+ if (S.RequireCompleteType(Loc, T, diag::err_temp_copy_incomplete))
return move(CurInit);
// Perform overload resolution using the class's copy/move constructors.
@@ -4516,7 +4515,7 @@
for (unsigned I = 1, N = Constructor->getNumParams(); I != N; ++I) {
ParmVarDecl *Parm = Constructor->getParamDecl(I);
if (S.RequireCompleteType(Loc, Parm->getType(),
- S.PDiag(diag::err_call_incomplete_argument)))
+ diag::err_call_incomplete_argument))
break;
// Build the default argument expression; we don't actually care
Modified: cfe/branches/tooling/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaLambda.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaLambda.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaLambda.cpp Tue May 8 03:47:31 2012
@@ -441,7 +441,10 @@
LambdaScopeInfo *LSI = getCurLambda();
CXXRecordDecl *Class = LSI->Lambda;
Class->setInvalidDecl();
- SmallVector<Decl*, 4> Fields(Class->field_begin(), Class->field_end());
+ SmallVector<Decl*, 4> Fields;
+ for (RecordDecl::field_iterator i = Class->field_begin(),
+ e = Class->field_end(); i != e; ++i)
+ Fields.push_back(&*i);
ActOnFields(0, Class->getLocation(), Class, Fields,
SourceLocation(), SourceLocation(), 0);
CheckCompletedCXXClass(Class);
@@ -704,7 +707,10 @@
addBlockPointerConversion(*this, IntroducerRange, Class, CallOperator);
// Finalize the lambda class.
- SmallVector<Decl*, 4> Fields(Class->field_begin(), Class->field_end());
+ SmallVector<Decl*, 4> Fields;
+ for (RecordDecl::field_iterator i = Class->field_begin(),
+ e = Class->field_end(); i != e; ++i)
+ Fields.push_back(&*i);
ActOnFields(0, Class->getLocation(), Class, Fields,
SourceLocation(), SourceLocation(), 0);
CheckCompletedCXXClass(Class);
Modified: cfe/branches/tooling/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaLookup.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaLookup.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaLookup.cpp Tue May 8 03:47:31 2012
@@ -1069,7 +1069,7 @@
for (Decl::redecl_iterator RD = D->redecls_begin(), RDEnd = D->redecls_end();
RD != RDEnd; ++RD) {
- if (NamedDecl *ND = dyn_cast<NamedDecl>(*RD)) {
+ if (NamedDecl *ND = dyn_cast<NamedDecl>(RD)) {
if (LookupResult::isVisible(ND))
return ND;
}
Modified: cfe/branches/tooling/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaObjCProperty.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaObjCProperty.cpp Tue May 8 03:47:31 2012
@@ -588,6 +588,9 @@
}
if (PropertyIvarLoc.isInvalid())
PropertyIvarLoc = PropertyLoc;
+ SourceLocation PropertyDiagLoc = PropertyLoc;
+ if (PropertyDiagLoc.isInvalid())
+ PropertyDiagLoc = ClassImpDecl->getLocStart();
ObjCPropertyDecl *property = 0;
ObjCInterfaceDecl* IDecl = 0;
// Find the class or category class where this property must have
@@ -654,6 +657,7 @@
return 0;
}
ObjCIvarDecl *Ivar = 0;
+ bool CompleteTypeErr = false;
// Check that we have a valid, previously declared ivar for @synthesize
if (Synthesize) {
// @synthesize
@@ -664,7 +668,14 @@
Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared);
QualType PropType = property->getType();
QualType PropertyIvarType = PropType.getNonReferenceType();
-
+
+ if (RequireCompleteType(PropertyDiagLoc, PropertyIvarType,
+ diag::err_incomplete_synthesized_property,
+ property->getDeclName())) {
+ Diag(property->getLocation(), diag::note_property_declare);
+ CompleteTypeErr = true;
+ }
+
if (getLangOpts().ObjCAutoRefCount &&
(property->getPropertyAttributesAsWritten() &
ObjCPropertyDecl::OBJC_PR_readonly) &&
@@ -680,7 +691,7 @@
getLangOpts().getGC() != LangOptions::NonGC) {
assert(!getLangOpts().ObjCAutoRefCount);
if (PropertyIvarType.isObjCGCStrong()) {
- Diag(PropertyLoc, diag::err_gc_weak_property_strong_type);
+ Diag(PropertyDiagLoc, diag::err_gc_weak_property_strong_type);
Diag(property->getLocation(), diag::note_property_declare);
} else {
PropertyIvarType =
@@ -699,7 +710,7 @@
// explicitly write an ownership attribute on the property.
if (!property->hasWrittenStorageAttribute() &&
!(kind & ObjCPropertyDecl::OBJC_PR_strong)) {
- Diag(PropertyLoc,
+ Diag(PropertyDiagLoc,
diag::err_arc_objc_property_default_assign_on_object);
Diag(property->getLocation(), diag::note_property_declare);
} else {
@@ -711,12 +722,12 @@
if (const ObjCObjectPointerType *ObjT =
PropertyIvarType->getAs<ObjCObjectPointerType>())
if (ObjT->getInterfaceDecl()->isArcWeakrefUnavailable()) {
- Diag(PropertyLoc, diag::err_arc_weak_unavailable_property);
+ Diag(PropertyDiagLoc, diag::err_arc_weak_unavailable_property);
Diag(property->getLocation(), diag::note_property_declare);
err = true;
}
if (!err && !getLangOpts().ObjCRuntimeHasWeak) {
- Diag(PropertyLoc, diag::err_arc_weak_no_runtime);
+ Diag(PropertyDiagLoc, diag::err_arc_weak_no_runtime);
Diag(property->getLocation(), diag::note_property_declare);
}
}
@@ -730,7 +741,7 @@
if (kind & ObjCPropertyDecl::OBJC_PR_weak &&
!getLangOpts().ObjCAutoRefCount &&
getLangOpts().getGC() == LangOptions::NonGC) {
- Diag(PropertyLoc, diag::error_synthesize_weak_non_arc_or_gc);
+ Diag(PropertyDiagLoc, diag::error_synthesize_weak_non_arc_or_gc);
Diag(property->getLocation(), diag::note_property_declare);
}
@@ -739,17 +750,20 @@
PropertyIvarType, /*Dinfo=*/0,
ObjCIvarDecl::Private,
(Expr *)0, true);
+ if (CompleteTypeErr)
+ Ivar->setInvalidDecl();
ClassImpDecl->addDecl(Ivar);
IDecl->makeDeclVisibleInContext(Ivar);
property->setPropertyIvarDecl(Ivar);
if (!getLangOpts().ObjCNonFragileABI)
- Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
+ Diag(PropertyDiagLoc, diag::error_missing_property_ivar_decl)
+ << PropertyId;
// Note! I deliberately want it to fall thru so, we have a
// a property implementation and to avoid future warnings.
} else if (getLangOpts().ObjCNonFragileABI &&
!declaresSameEntity(ClassDeclared, IDecl)) {
- Diag(PropertyLoc, diag::error_ivar_in_superclass_use)
+ Diag(PropertyDiagLoc, diag::error_ivar_in_superclass_use)
<< property->getDeclName() << Ivar->getDeclName()
<< ClassDeclared->getDeclName();
Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
@@ -773,7 +787,7 @@
== Compatible);
}
if (!compat) {
- Diag(PropertyLoc, diag::error_property_ivar_type)
+ Diag(PropertyDiagLoc, diag::error_property_ivar_type)
<< property->getDeclName() << PropType
<< Ivar->getDeclName() << IvarType;
Diag(Ivar->getLocation(), diag::note_ivar_decl);
@@ -788,7 +802,7 @@
QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType();
if (lhsType != rhsType &&
lhsType->isArithmeticType()) {
- Diag(PropertyLoc, diag::error_property_ivar_type)
+ Diag(PropertyDiagLoc, diag::error_property_ivar_type)
<< property->getDeclName() << PropType
<< Ivar->getDeclName() << IvarType;
Diag(Ivar->getLocation(), diag::note_ivar_decl);
@@ -797,7 +811,7 @@
// __weak is explicit. So it works on Canonical type.
if ((PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak() &&
getLangOpts().getGC() != LangOptions::NonGC)) {
- Diag(PropertyLoc, diag::error_weak_property)
+ Diag(PropertyDiagLoc, diag::error_weak_property)
<< property->getDeclName() << Ivar->getDeclName();
Diag(Ivar->getLocation(), diag::note_ivar_decl);
// Fall thru - see previous comment
@@ -806,7 +820,7 @@
if ((property->getType()->isObjCObjectPointerType() ||
PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak() &&
getLangOpts().getGC() != LangOptions::NonGC) {
- Diag(PropertyLoc, diag::error_strong_property)
+ Diag(PropertyDiagLoc, diag::error_strong_property)
<< property->getDeclName() << Ivar->getDeclName();
// Fall thru - see previous comment
}
@@ -815,7 +829,7 @@
checkARCPropertyImpl(*this, PropertyLoc, property, Ivar);
} else if (PropertyIvar)
// @dynamic
- Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl);
+ Diag(PropertyDiagLoc, diag::error_dynamic_property_ivar_decl);
assert (property && "ActOnPropertyImplDecl - property declaration missing");
ObjCPropertyImplDecl *PIDecl =
@@ -825,9 +839,13 @@
ObjCPropertyImplDecl::Synthesize
: ObjCPropertyImplDecl::Dynamic),
Ivar, PropertyIvarLoc);
+
+ if (CompleteTypeErr)
+ PIDecl->setInvalidDecl();
+
if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
getterMethod->createImplicitParams(Context, IDecl);
- if (getLangOpts().CPlusPlus && Synthesize &&
+ if (getLangOpts().CPlusPlus && Synthesize && !CompleteTypeErr &&
Ivar->getType()->isRecordType()) {
// For Objective-C++, need to synthesize the AST for the IVAR object to be
// returned by the getter as it must conform to C++'s copy-return rules.
@@ -862,8 +880,8 @@
}
if (ObjCMethodDecl *setterMethod = property->getSetterMethodDecl()) {
setterMethod->createImplicitParams(Context, IDecl);
- if (getLangOpts().CPlusPlus && Synthesize
- && Ivar->getType()->isRecordType()) {
+ if (getLangOpts().CPlusPlus && Synthesize && !CompleteTypeErr &&
+ Ivar->getType()->isRecordType()) {
// FIXME. Eventually we want to do this for Objective-C as well.
ImplicitParamDecl *SelfDecl = setterMethod->getSelfDecl();
DeclRefExpr *SelfExpr =
@@ -941,7 +959,7 @@
if (Synthesize)
if (ObjCPropertyImplDecl *PPIDecl =
CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) {
- Diag(PropertyLoc, diag::error_duplicate_ivar_use)
+ Diag(PropertyDiagLoc, diag::error_duplicate_ivar_use)
<< PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
<< PropertyIvar;
Diag(PPIDecl->getLocation(), diag::note_previous_use);
@@ -949,7 +967,7 @@
if (ObjCPropertyImplDecl *PPIDecl =
CatImplClass->FindPropertyImplDecl(PropertyId)) {
- Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
+ Diag(PropertyDiagLoc, diag::error_property_implemented) << PropertyId;
Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
return 0;
}
@@ -1059,11 +1077,11 @@
// FIXME: O(N^2)
for (ObjCInterfaceDecl::prop_iterator S = SDecl->prop_begin(),
E = SDecl->prop_end(); S != E; ++S) {
- ObjCPropertyDecl *SuperPDecl = (*S);
+ ObjCPropertyDecl *SuperPDecl = &*S;
// Does property in super class has declaration in current class?
for (ObjCInterfaceDecl::prop_iterator I = IDecl->prop_begin(),
E = IDecl->prop_end(); I != E; ++I) {
- ObjCPropertyDecl *PDecl = (*I);
+ ObjCPropertyDecl *PDecl = &*I;
if (SuperPDecl->getIdentifier() == PDecl->getIdentifier())
DiagnosePropertyMismatch(PDecl, SuperPDecl,
SDecl->getIdentifier());
@@ -1085,29 +1103,29 @@
if (!CatDecl->IsClassExtension())
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Pr = (*P);
+ ObjCPropertyDecl *Pr = &*P;
ObjCCategoryDecl::prop_iterator CP, CE;
// Is this property already in category's list of properties?
for (CP = CatDecl->prop_begin(), CE = CatDecl->prop_end(); CP!=CE; ++CP)
- if ((*CP)->getIdentifier() == Pr->getIdentifier())
+ if (CP->getIdentifier() == Pr->getIdentifier())
break;
if (CP != CE)
// Property protocol already exist in class. Diagnose any mismatch.
- DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier());
+ DiagnosePropertyMismatch(&*CP, Pr, PDecl->getIdentifier());
}
return;
}
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Pr = (*P);
+ ObjCPropertyDecl *Pr = &*P;
ObjCInterfaceDecl::prop_iterator CP, CE;
// Is this property already in class's list of properties?
for (CP = IDecl->prop_begin(), CE = IDecl->prop_end(); CP != CE; ++CP)
- if ((*CP)->getIdentifier() == Pr->getIdentifier())
+ if (CP->getIdentifier() == Pr->getIdentifier())
break;
if (CP != CE)
// Property protocol already exist in class. Diagnose any mismatch.
- DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier());
+ DiagnosePropertyMismatch(&*CP, Pr, PDecl->getIdentifier());
}
}
@@ -1223,7 +1241,7 @@
if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
E = IDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Prop = (*P);
+ ObjCPropertyDecl *Prop = &*P;
PropMap[Prop->getIdentifier()] = Prop;
}
// scan through class's protocols.
@@ -1236,7 +1254,7 @@
if (!CATDecl->IsClassExtension())
for (ObjCContainerDecl::prop_iterator P = CATDecl->prop_begin(),
E = CATDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Prop = (*P);
+ ObjCPropertyDecl *Prop = &*P;
PropMap[Prop->getIdentifier()] = Prop;
}
// scan through class's protocols.
@@ -1247,7 +1265,7 @@
else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Prop = (*P);
+ ObjCPropertyDecl *Prop = &*P;
ObjCPropertyDecl *PropertyFromSuper = SuperPropMap[Prop->getIdentifier()];
// Exclude property for protocols which conform to class's super-class,
// as super-class has to implement the property.
@@ -1273,7 +1291,7 @@
if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
E = IDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Prop = (*P);
+ ObjCPropertyDecl *Prop = &*P;
PropMap[Prop->getIdentifier()] = Prop;
}
for (ObjCInterfaceDecl::all_protocol_iterator
@@ -1284,7 +1302,7 @@
else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Prop = (*P);
+ ObjCPropertyDecl *Prop = &*P;
if (!PropMap.count(Prop->getIdentifier()))
PropMap[Prop->getIdentifier()] = Prop;
}
@@ -1316,7 +1334,7 @@
dyn_cast<ObjCInterfaceDecl>(CDecl)) {
for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
E = IDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Prop = (*P);
+ ObjCPropertyDecl *Prop = &*P;
if (Prop->getIdentifier() == II)
return Prop;
}
@@ -1333,7 +1351,7 @@
dyn_cast<ObjCProtocolDecl>(CDecl)) {
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
- ObjCPropertyDecl *Prop = (*P);
+ ObjCPropertyDecl *Prop = &*P;
if (Prop->getIdentifier() == II)
return Prop;
}
@@ -1402,11 +1420,16 @@
// aren't really synthesized at a particular location; they just exist.
// Saying that they are located at the @implementation isn't really going
// to help users.
- ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
- true,
- /* property = */ Prop->getIdentifier(),
- /* ivar = */ getDefaultSynthIvarName(Prop, Context),
- SourceLocation());
+ ObjCPropertyImplDecl *PIDecl = dyn_cast_or_null<ObjCPropertyImplDecl>(
+ ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
+ true,
+ /* property = */ Prop->getIdentifier(),
+ /* ivar = */ getDefaultSynthIvarName(Prop, Context),
+ SourceLocation()));
+ if (PIDecl) {
+ Diag(Prop->getLocation(), diag::warn_missing_explicit_synthesis);
+ Diag(IMPDecl->getLocation(), diag::not_while_in_implementation);
+ }
}
}
@@ -1437,7 +1460,7 @@
for (ObjCImplDecl::propimpl_iterator
I = IMPDecl->propimpl_begin(),
EI = IMPDecl->propimpl_end(); I != EI; ++I)
- PropImplMap.insert((*I)->getPropertyDecl());
+ PropImplMap.insert(I->getPropertyDecl());
for (llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>::iterator
P = PropMap.begin(), E = PropMap.end(); P != E; ++P) {
@@ -1487,7 +1510,7 @@
for (ObjCContainerDecl::prop_iterator I = IDecl->prop_begin(),
E = IDecl->prop_end();
I != E; ++I) {
- ObjCPropertyDecl *Property = (*I);
+ ObjCPropertyDecl *Property = &*I;
ObjCMethodDecl *GetterMethod = 0;
ObjCMethodDecl *SetterMethod = 0;
bool LookedUpGetterSetter = false;
@@ -1574,7 +1597,7 @@
for (ObjCImplementationDecl::propimpl_iterator
i = D->propimpl_begin(), e = D->propimpl_end(); i != e; ++i) {
- ObjCPropertyImplDecl *PID = *i;
+ ObjCPropertyImplDecl *PID = &*i;
if (PID->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize)
continue;
Modified: cfe/branches/tooling/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaOverload.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaOverload.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaOverload.cpp Tue May 8 03:47:31 2012
@@ -28,6 +28,7 @@
#include "clang/Basic/PartialDiagnostic.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/STLExtras.h"
#include <algorithm>
@@ -541,6 +542,7 @@
TemplateDeductionInfo &Info) {
OverloadCandidate::DeductionFailureInfo Result;
Result.Result = static_cast<unsigned>(TDK);
+ Result.HasDiagnostic = false;
Result.Data = 0;
switch (TDK) {
case Sema::TDK_Success:
@@ -567,6 +569,12 @@
case Sema::TDK_SubstitutionFailure:
Result.Data = Info.take();
+ if (Info.hasSFINAEDiagnostic()) {
+ PartialDiagnosticAt *Diag = new (Result.Diagnostic) PartialDiagnosticAt(
+ SourceLocation(), PartialDiagnostic::NullDiagnostic());
+ Info.takeSFINAEDiagnostic(*Diag);
+ Result.HasDiagnostic = true;
+ }
break;
case Sema::TDK_NonDeducedMismatch:
@@ -594,8 +602,12 @@
break;
case Sema::TDK_SubstitutionFailure:
- // FIXME: Destroy the template arugment list?
+ // FIXME: Destroy the template argument list?
Data = 0;
+ if (PartialDiagnosticAt *Diag = getSFINAEDiagnostic()) {
+ Diag->~PartialDiagnosticAt();
+ HasDiagnostic = false;
+ }
break;
// Unhandled
@@ -605,6 +617,13 @@
}
}
+PartialDiagnosticAt *
+OverloadCandidate::DeductionFailureInfo::getSFINAEDiagnostic() {
+ if (HasDiagnostic)
+ return static_cast<PartialDiagnosticAt*>(static_cast<void*>(Diagnostic));
+ return 0;
+}
+
TemplateParameter
OverloadCandidate::DeductionFailureInfo::getTemplateParameter() {
switch (static_cast<Sema::TemplateDeductionResult>(Result)) {
@@ -1657,7 +1676,7 @@
// We have already pre-calculated the promotion type, so this is trivial.
if (ToType->isIntegerType() &&
- !RequireCompleteType(From->getLocStart(), FromType, PDiag()))
+ !RequireCompleteType(From->getLocStart(), FromType, 0))
return Context.hasSameUnqualifiedType(ToType,
FromEnumType->getDecl()->getPromotionType());
}
@@ -1987,7 +2006,7 @@
if (getLangOpts().CPlusPlus &&
FromPointeeType->isRecordType() && ToPointeeType->isRecordType() &&
!Context.hasSameUnqualifiedType(FromPointeeType, ToPointeeType) &&
- !RequireCompleteType(From->getLocStart(), FromPointeeType, PDiag()) &&
+ !RequireCompleteType(From->getLocStart(), FromPointeeType, 0) &&
IsDerivedFrom(FromPointeeType, ToPointeeType)) {
ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr,
ToPointeeType,
@@ -2616,7 +2635,7 @@
QualType ToClass(ToTypePtr->getClass(), 0);
if (!Context.hasSameUnqualifiedType(FromClass, ToClass) &&
- !RequireCompleteType(From->getLocStart(), ToClass, PDiag()) &&
+ !RequireCompleteType(From->getLocStart(), ToClass, 0) &&
IsDerivedFrom(ToClass, FromClass)) {
ConvertedType = Context.getMemberPointerType(FromTypePtr->getPointeeType(),
ToClass.getTypePtr());
@@ -2923,7 +2942,7 @@
S.IsDerivedFrom(From->getType(), ToType)))
ConstructorsOnly = true;
- S.RequireCompleteType(From->getLocStart(), ToType, S.PDiag());
+ S.RequireCompleteType(From->getLocStart(), ToType, 0);
// RequireCompleteType may have returned true due to some invalid decl
// during template instantiation, but ToType may be complete enough now
// to try to recover.
@@ -3001,8 +3020,7 @@
// Enumerate conversion functions, if we're allowed to.
if (ConstructorsOnly || isa<InitListExpr>(From)) {
- } else if (S.RequireCompleteType(From->getLocStart(), From->getType(),
- S.PDiag(0) << From->getSourceRange())) {
+ } else if (S.RequireCompleteType(From->getLocStart(), From->getType(), 0)) {
// No conversion functions from incomplete types.
} else if (const RecordType *FromRecordType
= From->getType()->getAs<RecordType>()) {
@@ -3848,7 +3866,7 @@
ObjCLifetimeConversion = false;
if (UnqualT1 == UnqualT2) {
// Nothing to do.
- } else if (!RequireCompleteType(Loc, OrigT2, PDiag()) &&
+ } else if (!RequireCompleteType(Loc, OrigT2, 0) &&
IsDerivedFrom(UnqualT2, UnqualT1))
DerivedToBase = true;
else if (UnqualT1->isObjCObjectOrInterfaceType() &&
@@ -4313,7 +4331,7 @@
// We need a complete type for what follows. Incomplete types can never be
// initialized from init lists.
- if (S.RequireCompleteType(From->getLocStart(), ToType, S.PDiag()))
+ if (S.RequireCompleteType(From->getLocStart(), ToType, 0))
return Result;
// C++11 [over.ics.list]p2:
@@ -5026,13 +5044,7 @@
/// successful.
ExprResult
Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *From,
- const PartialDiagnostic &NotIntDiag,
- const PartialDiagnostic &IncompleteDiag,
- const PartialDiagnostic &ExplicitConvDiag,
- const PartialDiagnostic &ExplicitConvNote,
- const PartialDiagnostic &AmbigDiag,
- const PartialDiagnostic &AmbigNote,
- const PartialDiagnostic &ConvDiag,
+ ICEConvertDiagnoser &Diagnoser,
bool AllowScopedEnumerations) {
// We can't perform any more checking for type-dependent expressions.
if (From->isTypeDependent())
@@ -5056,13 +5068,25 @@
// expression of integral or enumeration type.
const RecordType *RecordTy = T->getAs<RecordType>();
if (!RecordTy || !getLangOpts().CPlusPlus) {
- if (NotIntDiag.getDiagID())
- Diag(Loc, NotIntDiag) << T << From->getSourceRange();
+ if (!Diagnoser.Suppress)
+ Diagnoser.diagnoseNotInt(*this, Loc, T) << From->getSourceRange();
return Owned(From);
}
// We must have a complete class type.
- if (RequireCompleteType(Loc, T, IncompleteDiag))
+ struct TypeDiagnoserPartialDiag : TypeDiagnoser {
+ ICEConvertDiagnoser &Diagnoser;
+ Expr *From;
+
+ TypeDiagnoserPartialDiag(ICEConvertDiagnoser &Diagnoser, Expr *From)
+ : TypeDiagnoser(Diagnoser.Suppress), Diagnoser(Diagnoser), From(From) {}
+
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ Diagnoser.diagnoseIncomplete(S, Loc, T) << From->getSourceRange();
+ }
+ } IncompleteDiagnoser(Diagnoser, From);
+
+ if (RequireCompleteType(Loc, T, IncompleteDiagnoser))
return Owned(From);
// Look for a conversion to an integral or enumeration type.
@@ -5092,7 +5116,7 @@
switch (ViableConversions.size()) {
case 0:
- if (ExplicitConversions.size() == 1 && ExplicitConvDiag.getDiagID()) {
+ if (ExplicitConversions.size() == 1 && !Diagnoser.Suppress) {
DeclAccessPair Found = ExplicitConversions[0];
CXXConversionDecl *Conversion
= cast<CXXConversionDecl>(Found->getUnderlyingDecl());
@@ -5104,14 +5128,12 @@
std::string TypeStr;
ConvTy.getAsStringInternal(TypeStr, getPrintingPolicy());
- Diag(Loc, ExplicitConvDiag)
- << T << ConvTy
+ Diagnoser.diagnoseExplicitConv(*this, Loc, T, ConvTy)
<< FixItHint::CreateInsertion(From->getLocStart(),
"static_cast<" + TypeStr + ">(")
<< FixItHint::CreateInsertion(PP.getLocForEndOfToken(From->getLocEnd()),
")");
- Diag(Conversion->getLocation(), ExplicitConvNote)
- << ConvTy->isEnumeralType() << ConvTy;
+ Diagnoser.noteExplicitConv(*this, Conversion, ConvTy);
// If we aren't in a SFINAE context, build a call to the
// explicit conversion function.
@@ -5142,12 +5164,12 @@
= cast<CXXConversionDecl>(Found->getUnderlyingDecl());
QualType ConvTy
= Conversion->getConversionType().getNonReferenceType();
- if (ConvDiag.getDiagID()) {
+ if (!Diagnoser.SuppressConversion) {
if (isSFINAEContext())
return ExprError();
- Diag(Loc, ConvDiag)
- << T << ConvTy->isEnumeralType() << ConvTy << From->getSourceRange();
+ Diagnoser.diagnoseConversion(*this, Loc, T, ConvTy)
+ << From->getSourceRange();
}
ExprResult Result = BuildCXXMemberCallExpr(From, Found, Conversion,
@@ -5163,24 +5185,24 @@
}
default:
- if (!AmbigDiag.getDiagID())
- return Owned(From);
+ if (Diagnoser.Suppress)
+ return ExprError();
- Diag(Loc, AmbigDiag)
- << T << From->getSourceRange();
+ Diagnoser.diagnoseAmbiguous(*this, Loc, T) << From->getSourceRange();
for (unsigned I = 0, N = ViableConversions.size(); I != N; ++I) {
CXXConversionDecl *Conv
= cast<CXXConversionDecl>(ViableConversions[I]->getUnderlyingDecl());
QualType ConvTy = Conv->getConversionType().getNonReferenceType();
- Diag(Conv->getLocation(), AmbigNote)
- << ConvTy->isEnumeralType() << ConvTy;
+ Diagnoser.noteAmbiguous(*this, Conv, ConvTy);
}
return Owned(From);
}
if (!isIntegralOrEnumerationType(From->getType(), AllowScopedEnumerations) &&
- NotIntDiag.getDiagID())
- Diag(Loc, NotIntDiag) << From->getType() << From->getSourceRange();
+ !Diagnoser.Suppress) {
+ Diagnoser.diagnoseNotInt(*this, Loc, From->getType())
+ << From->getSourceRange();
+ }
return DefaultLvalueConversion(From);
}
@@ -5906,7 +5928,7 @@
// empty.
if (const RecordType *T1Rec = T1->getAs<RecordType>()) {
// Complete the type if it can be completed. Otherwise, we're done.
- if (RequireCompleteType(OpLoc, T1, PDiag()))
+ if (RequireCompleteType(OpLoc, T1, 0))
return;
LookupResult Operators(*this, OpName, OpLoc, LookupOrdinaryName);
@@ -8232,14 +8254,29 @@
return;
case Sema::TDK_SubstitutionFailure: {
- std::string ArgString;
- if (TemplateArgumentList *Args
- = Cand->DeductionFailure.getTemplateArgumentList())
- ArgString = S.getTemplateArgumentBindingsText(
- Fn->getDescribedFunctionTemplate()->getTemplateParameters(),
- *Args);
+ // Format the template argument list into the argument string.
+ llvm::SmallString<128> TemplateArgString;
+ if (TemplateArgumentList *Args =
+ Cand->DeductionFailure.getTemplateArgumentList()) {
+ TemplateArgString = " ";
+ TemplateArgString += S.getTemplateArgumentBindingsText(
+ Fn->getDescribedFunctionTemplate()->getTemplateParameters(), *Args);
+ }
+
+ // Format the SFINAE diagnostic into the argument string.
+ // FIXME: Add a general mechanism to include a PartialDiagnostic *'s
+ // formatted message in another diagnostic.
+ llvm::SmallString<128> SFINAEArgString;
+ SourceRange R;
+ if (PartialDiagnosticAt *PDiag =
+ Cand->DeductionFailure.getSFINAEDiagnostic()) {
+ SFINAEArgString = ": ";
+ R = SourceRange(PDiag->first, PDiag->first);
+ PDiag->second.EmitToString(S.getDiagnostics(), SFINAEArgString);
+ }
+
S.Diag(Fn->getLocation(), diag::note_ovl_candidate_substitution_failure)
- << ArgString;
+ << TemplateArgString << SFINAEArgString << R;
MaybeEmitInheritedConstructorNote(S, Fn);
return;
}
@@ -10610,8 +10647,7 @@
DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(OO_Call);
if (RequireCompleteType(LParenLoc, Object.get()->getType(),
- PDiag(diag::err_incomplete_object_call)
- << Object.get()->getSourceRange()))
+ diag::err_incomplete_object_call, Object.get()))
return true;
LookupResult R(*this, OpName, LParenLoc, LookupOrdinaryName);
@@ -10899,8 +10935,7 @@
const RecordType *BaseRecord = Base->getType()->getAs<RecordType>();
if (RequireCompleteType(Loc, Base->getType(),
- PDiag(diag::err_typecheck_incomplete_tag)
- << Base->getSourceRange()))
+ diag::err_typecheck_incomplete_tag, Base))
return ExprError();
LookupResult R(*this, OpName, OpLoc, LookupOrdinaryName);
Modified: cfe/branches/tooling/lib/Sema/SemaPseudoObject.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaPseudoObject.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaPseudoObject.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaPseudoObject.cpp Tue May 8 03:47:31 2012
@@ -889,8 +889,7 @@
// We must have a complete class type.
if (RequireCompleteType(FromE->getExprLoc(), T,
- PDiag(diag::err_objc_index_incomplete_class_type)
- << FromE->getSourceRange()))
+ diag::err_objc_index_incomplete_class_type, FromE))
return OS_Error;
// Look for a conversion to an integral, enumeration type, or
Modified: cfe/branches/tooling/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaStmt.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaStmt.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaStmt.cpp Tue May 8 03:47:31 2012
@@ -19,6 +19,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/StmtObjC.h"
@@ -28,6 +29,7 @@
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
using namespace clang;
using namespace sema;
@@ -519,16 +521,56 @@
if (!Cond)
return StmtError();
+ class SwitchConvertDiagnoser : public ICEConvertDiagnoser {
+ Expr *Cond;
+
+ public:
+ SwitchConvertDiagnoser(Expr *Cond)
+ : ICEConvertDiagnoser(false, true), Cond(Cond) { }
+
+ virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_typecheck_statement_requires_integer) << T;
+ }
+
+ virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_switch_incomplete_class_type)
+ << T << Cond->getSourceRange();
+ }
+
+ virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return S.Diag(Loc, diag::err_switch_explicit_conversion) << T << ConvTy;
+ }
+
+ virtual DiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return S.Diag(Conv->getLocation(), diag::note_switch_conversion)
+ << ConvTy->isEnumeralType() << ConvTy;
+ }
+
+ virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
+ QualType T) {
+ return S.Diag(Loc, diag::err_switch_multiple_conversions) << T;
+ }
+
+ virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv,
+ QualType ConvTy) {
+ return S.Diag(Conv->getLocation(), diag::note_switch_conversion)
+ << ConvTy->isEnumeralType() << ConvTy;
+ }
+
+ virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc,
+ QualType T,
+ QualType ConvTy) {
+ return DiagnosticBuilder::getEmpty();
+ }
+ } SwitchDiagnoser(Cond);
+
CondResult
- = ConvertToIntegralOrEnumerationType(SwitchLoc, Cond,
- PDiag(diag::err_typecheck_statement_requires_integer),
- PDiag(diag::err_switch_incomplete_class_type)
- << Cond->getSourceRange(),
- PDiag(diag::err_switch_explicit_conversion),
- PDiag(diag::note_switch_conversion),
- PDiag(diag::err_switch_multiple_conversions),
- PDiag(diag::note_switch_conversion),
- PDiag(0),
+ = ConvertToIntegralOrEnumerationType(SwitchLoc, Cond, SwitchDiagnoser,
/*AllowScopedEnumerations*/ true);
if (CondResult.isInvalid()) return StmtError();
Cond = CondResult.take();
@@ -876,7 +918,7 @@
EDI != ED->enumerator_end(); ++EDI) {
llvm::APSInt Val = EDI->getInitVal();
AdjustAPSInt(Val, CondWidth, CondIsSigned);
- EnumVals.push_back(std::make_pair(Val, *EDI));
+ EnumVals.push_back(std::make_pair(Val, &*EDI));
}
std::stable_sort(EnumVals.begin(), EnumVals.end(), CmpEnumVals);
EnumValsTy::iterator EIend =
@@ -1037,6 +1079,219 @@
return Owned(new (Context) DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen));
}
+namespace {
+ // This visitor will traverse a conditional statement and store all
+ // the evaluated decls into a vector. Simple is set to true if none
+ // of the excluded constructs are used.
+ class DeclExtractor : public EvaluatedExprVisitor<DeclExtractor> {
+ llvm::SmallPtrSet<VarDecl*, 8> &Decls;
+ llvm::SmallVector<SourceRange, 10> &Ranges;
+ bool Simple;
+ PartialDiagnostic &PDiag;
+public:
+ typedef EvaluatedExprVisitor<DeclExtractor> Inherited;
+
+ DeclExtractor(Sema &S, llvm::SmallPtrSet<VarDecl*, 8> &Decls,
+ llvm::SmallVector<SourceRange, 10> &Ranges,
+ PartialDiagnostic &PDiag) :
+ Inherited(S.Context),
+ Decls(Decls),
+ Ranges(Ranges),
+ Simple(true),
+ PDiag(PDiag) {}
+
+ bool isSimple() { return Simple; }
+
+ // Replaces the method in EvaluatedExprVisitor.
+ void VisitMemberExpr(MemberExpr* E) {
+ Simple = false;
+ }
+
+ // Any Stmt not whitelisted will cause the condition to be marked complex.
+ void VisitStmt(Stmt *S) {
+ Simple = false;
+ }
+
+ void VisitBinaryOperator(BinaryOperator *E) {
+ Visit(E->getLHS());
+ Visit(E->getRHS());
+ }
+
+ void VisitCastExpr(CastExpr *E) {
+ Visit(E->getSubExpr());
+ }
+
+ void VisitUnaryOperator(UnaryOperator *E) {
+ // Skip checking conditionals with derefernces.
+ if (E->getOpcode() == UO_Deref)
+ Simple = false;
+ else
+ Visit(E->getSubExpr());
+ }
+
+ void VisitConditionalOperator(ConditionalOperator *E) {
+ Visit(E->getCond());
+ Visit(E->getTrueExpr());
+ Visit(E->getFalseExpr());
+ }
+
+ void VisitParenExpr(ParenExpr *E) {
+ Visit(E->getSubExpr());
+ }
+
+ void VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
+ Visit(E->getOpaqueValue()->getSourceExpr());
+ Visit(E->getFalseExpr());
+ }
+
+ void VisitIntegerLiteral(IntegerLiteral *E) { }
+ void VisitFloatingLiteral(FloatingLiteral *E) { }
+ void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { }
+ void VisitCharacterLiteral(CharacterLiteral *E) { }
+ void VisitGNUNullExpr(GNUNullExpr *E) { }
+ void VisitImaginaryLiteral(ImaginaryLiteral *E) { }
+
+ void VisitDeclRefExpr(DeclRefExpr *E) {
+ VarDecl *VD = dyn_cast<VarDecl>(E->getDecl());
+ if (!VD) return;
+
+ Ranges.push_back(E->getSourceRange());
+
+ Decls.insert(VD);
+ }
+
+ }; // end class DeclExtractor
+
+ // DeclMatcher checks to see if the decls are used in a non-evauluated
+ // context.
+ class DeclMatcher : public EvaluatedExprVisitor<DeclMatcher> {
+ llvm::SmallPtrSet<VarDecl*, 8> &Decls;
+ bool FoundDecl;
+ //bool EvalDecl;
+
+public:
+ typedef EvaluatedExprVisitor<DeclMatcher> Inherited;
+
+ DeclMatcher(Sema &S, llvm::SmallPtrSet<VarDecl*, 8> &Decls, Stmt *Statement) :
+ Inherited(S.Context), Decls(Decls), FoundDecl(false) {
+ if (!Statement) return;
+
+ Visit(Statement);
+ }
+
+ void VisitReturnStmt(ReturnStmt *S) {
+ FoundDecl = true;
+ }
+
+ void VisitBreakStmt(BreakStmt *S) {
+ FoundDecl = true;
+ }
+
+ void VisitGotoStmt(GotoStmt *S) {
+ FoundDecl = true;
+ }
+
+ void VisitCastExpr(CastExpr *E) {
+ if (E->getCastKind() == CK_LValueToRValue)
+ CheckLValueToRValueCast(E->getSubExpr());
+ else
+ Visit(E->getSubExpr());
+ }
+
+ void CheckLValueToRValueCast(Expr *E) {
+ E = E->IgnoreParenImpCasts();
+
+ if (isa<DeclRefExpr>(E)) {
+ return;
+ }
+
+ if (ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) {
+ Visit(CO->getCond());
+ CheckLValueToRValueCast(CO->getTrueExpr());
+ CheckLValueToRValueCast(CO->getFalseExpr());
+ return;
+ }
+
+ if (BinaryConditionalOperator *BCO =
+ dyn_cast<BinaryConditionalOperator>(E)) {
+ CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
+ CheckLValueToRValueCast(BCO->getFalseExpr());
+ return;
+ }
+
+ Visit(E);
+ }
+
+ void VisitDeclRefExpr(DeclRefExpr *E) {
+ if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()))
+ if (Decls.count(VD))
+ FoundDecl = true;
+ }
+
+ bool FoundDeclInUse() { return FoundDecl; }
+
+ }; // end class DeclMatcher
+
+ void CheckForLoopConditionalStatement(Sema &S, Expr *Second,
+ Expr *Third, Stmt *Body) {
+ // Condition is empty
+ if (!Second) return;
+
+ if (S.Diags.getDiagnosticLevel(diag::warn_variables_not_in_loop_body,
+ Second->getLocStart())
+ == DiagnosticsEngine::Ignored)
+ return;
+
+ PartialDiagnostic PDiag = S.PDiag(diag::warn_variables_not_in_loop_body);
+ llvm::SmallPtrSet<VarDecl*, 8> Decls;
+ llvm::SmallVector<SourceRange, 10> Ranges;
+ DeclExtractor DE(S, Decls, Ranges, PDiag);
+ DE.Visit(Second);
+
+ // Don't analyze complex conditionals.
+ if (!DE.isSimple()) return;
+
+ // No decls found.
+ if (Decls.size() == 0) return;
+
+ // Don't warn on volatile, static, or global variables.
+ for (llvm::SmallPtrSet<VarDecl*, 8>::iterator I = Decls.begin(),
+ E = Decls.end();
+ I != E; ++I)
+ if ((*I)->getType().isVolatileQualified() ||
+ (*I)->hasGlobalStorage()) return;
+
+ if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
+ DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
+ DeclMatcher(S, Decls, Body).FoundDeclInUse())
+ return;
+
+ // Load decl names into diagnostic.
+ if (Decls.size() > 4)
+ PDiag << 0;
+ else {
+ PDiag << Decls.size();
+ for (llvm::SmallPtrSet<VarDecl*, 8>::iterator I = Decls.begin(),
+ E = Decls.end();
+ I != E; ++I)
+ PDiag << (*I)->getDeclName();
+ }
+
+ // Load SourceRanges into diagnostic if there is room.
+ // Otherwise, load the SourceRange of the conditional expression.
+ if (Ranges.size() <= PartialDiagnostic::MaxArguments)
+ for (llvm::SmallVector<SourceRange, 10>::iterator I = Ranges.begin(),
+ E = Ranges.end();
+ I != E; ++I)
+ PDiag << *I;
+ else
+ PDiag << Second->getSourceRange();
+
+ S.Diag(Ranges.begin()->getBegin(), PDiag);
+ }
+
+} // end namespace
+
StmtResult
Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Stmt *First, FullExprArg second, Decl *secondVar,
@@ -1059,6 +1314,8 @@
}
}
+ CheckForLoopConditionalStatement(*this, second.get(), third.get(), Body);
+
ExprResult SecondResult(second.release());
VarDecl *ConditionVar = 0;
if (secondVar) {
@@ -1133,9 +1390,9 @@
if (iface &&
RequireCompleteType(forLoc, QualType(objectType, 0),
getLangOpts().ObjCAutoRefCount
- ? PDiag(diag::err_arc_collection_forward)
- << collection->getSourceRange()
- : PDiag(0))) {
+ ? diag::err_arc_collection_forward
+ : 0,
+ collection)) {
// Otherwise, if we have any useful type information, check that
// the type declares the appropriate method.
} else if (iface || !objectType->qual_empty()) {
@@ -1442,7 +1699,7 @@
QualType RangeType = Range->getType();
if (RequireCompleteType(RangeLoc, RangeType,
- PDiag(diag::err_for_range_incomplete_type)))
+ diag::err_for_range_incomplete_type))
return StmtError();
// Build auto __begin = begin-expr, __end = end-expr.
Modified: cfe/branches/tooling/lib/Sema/SemaStmtAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaStmtAttr.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaStmtAttr.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaStmtAttr.cpp Tue May 8 03:47:31 2012
@@ -15,20 +15,46 @@
#include "TargetAttributesSema.h"
#include "clang/AST/ASTContext.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
#include "clang/Sema/DelayedDiagnostic.h"
#include "clang/Sema/Lookup.h"
+#include "clang/Sema/ScopeInfo.h"
#include "llvm/ADT/StringExtras.h"
+
using namespace clang;
using namespace sema;
+static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const AttributeList &A,
+ SourceRange Range) {
+ if (!isa<NullStmt>(St)) {
+ S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target)
+ << St->getLocStart();
+ if (isa<SwitchCase>(St)) {
+ SourceLocation L = Lexer::getLocForEndOfToken(Range.getEnd(), 0,
+ S.getSourceManager(), S.getLangOpts());
+ S.Diag(L, diag::note_fallthrough_insert_semi_fixit)
+ << FixItHint::CreateInsertion(L, ";");
+ }
+ return 0;
+ }
+ if (S.getCurFunction()->SwitchStack.empty()) {
+ S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_outside_switch);
+ return 0;
+ }
+ return ::new (S.Context) FallThroughAttr(A.getRange(), S.Context);
+}
+
-static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const AttributeList &A) {
+static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const AttributeList &A,
+ SourceRange Range) {
switch (A.getKind()) {
+ case AttributeList::AT_clang___fallthrough:
+ return handleFallThroughAttr(S, St, A, Range);
default:
// if we're here, then we parsed an attribute, but didn't recognize it as a
// statement attribute => it is declaration attribute
- S.Diag(A.getRange().getBegin(), diag::warn_attribute_invalid_on_stmt) <<
- A.getName()->getName();
+ S.Diag(A.getRange().getBegin(), diag::warn_attribute_invalid_on_stmt)
+ << A.getName()->getName() << St->getLocStart();
return 0;
}
}
@@ -37,7 +63,7 @@
SourceRange Range) {
AttrVec Attrs;
for (const AttributeList* l = AttrList; l; l = l->getNext()) {
- if (Attr *a = ProcessStmtAttribute(*this, S, *l))
+ if (Attr *a = ProcessStmtAttribute(*this, S, *l, Range))
Attrs.push_back(a);
}
Modified: cfe/branches/tooling/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaTemplate.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaTemplate.cpp Tue May 8 03:47:31 2012
@@ -354,12 +354,14 @@
return;
}
- if (S && !ObjectType.isNull() && !ObjectTypeSearchedInScope) {
- // C++ [basic.lookup.classref]p1:
+ if (S && !ObjectType.isNull() && !ObjectTypeSearchedInScope &&
+ !(getLangOpts().CPlusPlus0x && !Found.empty())) {
+ // C++03 [basic.lookup.classref]p1:
// [...] If the lookup in the class of the object expression finds a
// template, the name is also looked up in the context of the entire
// postfix-expression and [...]
//
+ // Note: C++11 does not perform this second lookup.
LookupResult FoundOuter(*this, Found.getLookupName(), Found.getNameLoc(),
LookupOrdinaryName);
LookupName(FoundOuter, S);
@@ -2562,6 +2564,7 @@
SourceRange(TemplateLoc, RAngleLoc));
Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
+ EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
return SemaRef.SubstExpr(Param->getDefaultArgument(), AllTemplateArgs);
}
@@ -4110,8 +4113,20 @@
Diag(Param->getLocation(), diag::note_template_param_here);
return ExprError();
} else if (!Arg->isValueDependent()) {
- Arg = VerifyIntegerConstantExpression(Arg, &Value,
- PDiag(diag::err_template_arg_not_ice) << ArgType, false).take();
+ class TmplArgICEDiagnoser : public VerifyICEDiagnoser {
+ QualType T;
+
+ public:
+ TmplArgICEDiagnoser(QualType T) : T(T) { }
+
+ virtual void diagnoseNotICE(Sema &S, SourceLocation Loc,
+ SourceRange SR) {
+ S.Diag(Loc, diag::err_template_arg_not_ice) << T << SR;
+ }
+ } Diagnoser(ArgType);
+
+ Arg = VerifyIntegerConstantExpression(Arg, &Value, Diagnoser,
+ false).take();
if (!Arg)
return ExprError();
}
Modified: cfe/branches/tooling/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaTemplateDeduction.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaTemplateDeduction.cpp Tue May 8 03:47:31 2012
@@ -2825,9 +2825,7 @@
QualType PointeeType = ParamRefType->getPointeeType();
// If the argument has incomplete array type, try to complete it's type.
- if (ArgType->isIncompleteArrayType() &&
- !S.RequireCompleteExprType(Arg, S.PDiag(),
- std::make_pair(SourceLocation(), S.PDiag())))
+ if (ArgType->isIncompleteArrayType() && !S.RequireCompleteExprType(Arg, 0))
ArgType = Arg->getType();
// [C++0x] If P is an rvalue reference to a cv-unqualified
Modified: cfe/branches/tooling/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaTemplateInstantiate.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaTemplateInstantiate.cpp Tue May 8 03:47:31 2012
@@ -1595,6 +1595,9 @@
NewParm->setUnparsedDefaultArg();
UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
} else if (Expr *Arg = OldParm->getDefaultArg())
+ // FIXME: if we non-lazily instantiated non-dependent default args for
+ // non-dependent parameter types we could remove a bunch of duplicate
+ // conversion warnings for such arguments.
NewParm->setUninstantiatedDefaultArg(Arg);
NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg());
Modified: cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue May 8 03:47:31 2012
@@ -671,7 +671,7 @@
}
if (EnumConst) {
- SemaRef.InstantiateAttrs(TemplateArgs, *EC, EnumConst);
+ SemaRef.InstantiateAttrs(TemplateArgs, &*EC, EnumConst);
EnumConst->setAccess(Enum->getAccess());
Enum->addDecl(EnumConst);
@@ -682,7 +682,7 @@
!Enum->isScoped()) {
// If the enumeration is within a function or method, record the enum
// constant as a local.
- SemaRef.CurrentInstantiationScope->InstantiatedLocal(*EC, EnumConst);
+ SemaRef.CurrentInstantiationScope->InstantiatedLocal(&*EC, EnumConst);
}
}
}
@@ -2354,9 +2354,10 @@
NoexceptExpr = E.take();
if (!NoexceptExpr->isTypeDependent() &&
!NoexceptExpr->isValueDependent())
- NoexceptExpr = SemaRef.VerifyIntegerConstantExpression(NoexceptExpr,
- 0, SemaRef.PDiag(diag::err_noexcept_needs_constant_expression),
- /*AllowFold*/ false).take();
+ NoexceptExpr
+ = SemaRef.VerifyIntegerConstantExpression(NoexceptExpr,
+ 0, diag::err_noexcept_needs_constant_expression,
+ /*AllowFold*/ false).take();
}
}
Modified: cfe/branches/tooling/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/SemaType.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/SemaType.cpp (original)
+++ cfe/branches/tooling/lib/Sema/SemaType.cpp Tue May 8 03:47:31 2012
@@ -561,7 +561,7 @@
/*const qualifier*/SourceLocation(),
/*volatile qualifier*/SourceLocation(),
/*mutable qualifier*/SourceLocation(),
- /*EH*/ EST_None, SourceLocation(), 0, 0, 0, 0, 0,
+ /*EH*/ EST_None, SourceLocation(), 0, 0, 0, 0,
/*parens*/ loc, loc,
declarator));
@@ -1205,9 +1205,20 @@
static bool isArraySizeVLA(Sema &S, Expr *ArraySize, llvm::APSInt &SizeVal) {
// If the size is an ICE, it certainly isn't a VLA. If we're in a GNU mode
// (like gnu99, but not c99) accept any evaluatable value as an extension.
- return S.VerifyIntegerConstantExpression(
- ArraySize, &SizeVal, S.PDiag(), S.LangOpts.GNUMode,
- S.PDiag(diag::ext_vla_folded_to_constant)).isInvalid();
+ class VLADiagnoser : public Sema::VerifyICEDiagnoser {
+ public:
+ VLADiagnoser() : Sema::VerifyICEDiagnoser(true) {}
+
+ virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) {
+ }
+
+ virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR) {
+ S.Diag(Loc, diag::ext_vla_folded_to_constant) << SR;
+ }
+ } Diagnoser;
+
+ return S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,
+ S.LangOpts.GNUMode).isInvalid();
}
@@ -4043,14 +4054,12 @@
/// case of a reference type, the referred-to type).
///
/// \param E The expression whose type is required to be complete.
-/// \param PD The partial diagnostic that will be printed out if the type cannot
-/// be completed.
+/// \param Diagnoser The object that will emit a diagnostic if the type is
+/// incomplete.
///
/// \returns \c true if the type of \p E is incomplete and diagnosed, \c false
/// otherwise.
-bool Sema::RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD,
- std::pair<SourceLocation,
- PartialDiagnostic> Note) {
+bool Sema::RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser){
QualType T = E->getType();
// Fast path the case where the type is already complete.
@@ -4107,7 +4116,26 @@
if (const ReferenceType *Ref = T->getAs<ReferenceType>())
T = Ref->getPointeeType();
- return RequireCompleteType(E->getExprLoc(), T, PD, Note);
+ return RequireCompleteType(E->getExprLoc(), T, Diagnoser);
+}
+
+namespace {
+ struct TypeDiagnoserDiag : Sema::TypeDiagnoser {
+ unsigned DiagID;
+
+ TypeDiagnoserDiag(unsigned DiagID)
+ : Sema::TypeDiagnoser(DiagID == 0), DiagID(DiagID) {}
+
+ virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ if (Suppressed) return;
+ S.Diag(Loc, DiagID) << T;
+ }
+ };
+}
+
+bool Sema::RequireCompleteExprType(Expr *E, unsigned DiagID) {
+ TypeDiagnoserDiag Diagnoser(DiagID);
+ return RequireCompleteExprType(E, Diagnoser);
}
/// @brief Ensure that the type T is a complete type.
@@ -4131,11 +4159,7 @@
/// @returns @c true if @p T is incomplete and a diagnostic was emitted,
/// @c false otherwise.
bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD,
- std::pair<SourceLocation,
- PartialDiagnostic> Note) {
- unsigned diag = PD.getDiagID();
-
+ TypeDiagnoser &Diagnoser) {
// FIXME: Add this assertion to make sure we always get instantiation points.
// assert(!Loc.isInvalid() && "Invalid location in RequireCompleteType");
// FIXME: Add this assertion to help us flush out problems with
@@ -4148,7 +4172,7 @@
NamedDecl *Def = 0;
if (!T->isIncompleteType(&Def)) {
// If we know about the definition but it is not visible, complain.
- if (diag != 0 && Def && !LookupResult::isVisible(Def)) {
+ if (!Diagnoser.Suppressed && Def && !LookupResult::isVisible(Def)) {
// Suppress this error outside of a SFINAE context if we've already
// emitted the error once for this type. There's no usefulness in
// repeating the diagnostic.
@@ -4204,7 +4228,7 @@
if (ClassTemplateSpec->getSpecializationKind() == TSK_Undeclared)
return InstantiateClassTemplateSpecialization(Loc, ClassTemplateSpec,
TSK_ImplicitInstantiation,
- /*Complain=*/diag != 0);
+ /*Complain=*/!Diagnoser.Suppressed);
} else if (CXXRecordDecl *Rec
= dyn_cast<CXXRecordDecl>(Record->getDecl())) {
CXXRecordDecl *Pattern = Rec->getInstantiatedFromMemberClass();
@@ -4216,20 +4240,16 @@
return InstantiateClass(Loc, Rec, Pattern,
getTemplateInstantiationArgs(Rec),
TSK_ImplicitInstantiation,
- /*Complain=*/diag != 0);
+ /*Complain=*/!Diagnoser.Suppressed);
}
}
}
- if (diag == 0)
+ if (Diagnoser.Suppressed)
return true;
-
+
// We have an incomplete type. Produce a diagnostic.
- Diag(Loc, PD) << T;
-
- // If we have a note, produce it.
- if (!Note.first.isInvalid())
- Diag(Note.first, Note.second);
+ Diagnoser.diagnose(*this, Loc, T);
// If the type was a forward declaration of a class/struct/union
// type, produce a note.
@@ -4247,15 +4267,9 @@
}
bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD) {
- return RequireCompleteType(Loc, T, PD,
- std::make_pair(SourceLocation(), PDiag(0)));
-}
-
-bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
- unsigned DiagID) {
- return RequireCompleteType(Loc, T, PDiag(DiagID),
- std::make_pair(SourceLocation(), PDiag(0)));
+ unsigned DiagID) {
+ TypeDiagnoserDiag Diagnoser(DiagID);
+ return RequireCompleteType(Loc, T, Diagnoser);
}
/// @brief Ensure that the type T is a literal type.
@@ -4272,13 +4286,12 @@
///
/// @param T The type that this routine is examining for literalness.
///
-/// @param PD The partial diagnostic that will be printed out if T is not a
-/// literal type.
+/// @param Diagnoser Emits a diagnostic if T is not a literal type.
///
/// @returns @c true if @p T is not a literal type and a diagnostic was emitted,
/// @c false otherwise.
bool Sema::RequireLiteralType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD) {
+ TypeDiagnoser &Diagnoser) {
assert(!T->isDependentType() && "type should not be dependent");
QualType ElemType = Context.getBaseElementType(T);
@@ -4287,10 +4300,10 @@
if (T->isLiteralType())
return false;
- if (PD.getDiagID() == 0)
+ if (Diagnoser.Suppressed)
return true;
- Diag(Loc, PD) << T;
+ Diagnoser.diagnose(*this, Loc, T);
if (T->isVariableArrayType())
return true;
@@ -4305,8 +4318,7 @@
// class type must have a trivial destructor (which can't be checked until
// the class definition is complete).
if (!RD->isCompleteDefinition()) {
- RequireCompleteType(Loc, ElemType,
- PDiag(diag::note_non_literal_incomplete) << T);
+ RequireCompleteType(Loc, ElemType, diag::note_non_literal_incomplete, T);
return true;
}
@@ -4336,11 +4348,11 @@
}
for (CXXRecordDecl::field_iterator I = RD->field_begin(),
E = RD->field_end(); I != E; ++I) {
- if (!(*I)->getType()->isLiteralType() ||
- (*I)->getType().isVolatileQualified()) {
- Diag((*I)->getLocation(), diag::note_non_literal_field)
- << RD << (*I) << (*I)->getType()
- << (*I)->getType().isVolatileQualified();
+ if (!I->getType()->isLiteralType() ||
+ I->getType().isVolatileQualified()) {
+ Diag(I->getLocation(), diag::note_non_literal_field)
+ << RD << &*I << I->getType()
+ << I->getType().isVolatileQualified();
return true;
}
}
@@ -4360,6 +4372,11 @@
return true;
}
+bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID) {
+ TypeDiagnoserDiag Diagnoser(DiagID);
+ return RequireLiteralType(Loc, T, Diagnoser);
+}
+
/// \brief Retrieve a version of the type 'T' that is elaborated by Keyword
/// and qualified by the nested-name-specifier contained in SS.
QualType Sema::getElaboratedType(ElaboratedTypeKeyword Keyword,
@@ -4487,8 +4504,7 @@
if (!T->isDependentType()) {
// FIXME: It isn't entirely clear whether incomplete atomic types
// are allowed or not; for simplicity, ban them for the moment.
- if (RequireCompleteType(Loc, T,
- PDiag(diag::err_atomic_specifier_bad_type) << 0))
+ if (RequireCompleteType(Loc, T, diag::err_atomic_specifier_bad_type, 0))
return QualType();
int DisallowedKind = -1;
Modified: cfe/branches/tooling/lib/Sema/TargetAttributesSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Sema/TargetAttributesSema.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Sema/TargetAttributesSema.cpp (original)
+++ cfe/branches/tooling/lib/Sema/TargetAttributesSema.cpp Tue May 8 03:47:31 2012
@@ -182,16 +182,6 @@
return;
}
- // The attribute is also overridden by a subsequent declaration as dllexport.
- // Warning is emitted.
- for (AttributeList *nextAttr = Attr.getNext(); nextAttr;
- nextAttr = nextAttr->getNext()) {
- if (nextAttr->getKind() == AttributeList::AT_dllexport) {
- S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
- return;
- }
- }
-
if (D->getAttr<DLLExportAttr>()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
return;
@@ -228,6 +218,11 @@
return;
}
+ if (DLLImportAttr *Import = D->getAttr<DLLImportAttr>()) {
+ S.Diag(Import->getLocation(), diag::warn_attribute_ignored) << "dllimport";
+ D->dropAttr<DLLImportAttr>();
+ }
+
D->addAttr(::new (S.Context) DLLExportAttr(Attr.getLoc(), S.Context));
}
Modified: cfe/branches/tooling/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Serialization/ASTReader.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Serialization/ASTReader.cpp (original)
+++ cfe/branches/tooling/lib/Serialization/ASTReader.cpp Tue May 8 03:47:31 2012
@@ -2473,6 +2473,26 @@
Error("source location entry is incorrect");
return Failure;
}
+
+ off_t StoredSize = (off_t)Record[4];
+ time_t StoredTime = (time_t)Record[5];
+
+ // Check if there was a request to override the contents of the file
+ // that was part of the precompiled header. Overridding such a file
+ // can lead to problems when lexing using the source locations from the
+ // PCH.
+ SourceManager &SM = getSourceManager();
+ if (SM.isFileOverridden(File)) {
+ Error(diag::err_fe_pch_file_overridden, Filename);
+ // After emitting the diagnostic, recover by disabling the override so
+ // that the original file will be used.
+ SM.disableFileContentsOverride(File);
+ // The FileEntry is a virtual file entry with the size of the contents
+ // that would override the original contents. Set it to the original's
+ // size/time.
+ FileMgr.modifyFileEntry(const_cast<FileEntry*>(File),
+ StoredSize, StoredTime);
+ }
// The stat info from the FileEntry came from the cached stat
// info of the PCH, so we cannot trust it.
@@ -2482,12 +2502,12 @@
StatBuf.st_mtime = File->getModificationTime();
}
- if (((off_t)Record[4] != StatBuf.st_size
+ if ((StoredSize != StatBuf.st_size
#if !defined(LLVM_ON_WIN32)
// In our regression testing, the Windows file system seems to
// have inconsistent modification times that sometimes
// erroneously trigger this error-handling path.
- || (time_t)Record[5] != StatBuf.st_mtime
+ || StoredTime != StatBuf.st_mtime
#endif
)) {
Error(diag::err_fe_pch_file_modified, Filename);
@@ -5025,6 +5045,7 @@
I = Decls.begin(), E = Decls.end(); I != E; ++I) {
SetExternalVisibleDeclsForName(DC, I->first, I->second);
}
+ const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false);
}
/// \brief Under non-PCH compilation the consumer receives the objc methods
@@ -5037,7 +5058,7 @@
for (ObjCImplDecl::method_iterator
I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I)
- Consumer->HandleInterestingDecl(DeclGroupRef(*I));
+ Consumer->HandleInterestingDecl(DeclGroupRef(&*I));
Consumer->HandleInterestingDecl(DeclGroupRef(ImplD));
}
@@ -6227,18 +6248,19 @@
/// \brief Record that the given ID maps to the given switch-case
/// statement.
void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) {
- assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID");
- SwitchCaseStmts[ID] = SC;
+ assert((*CurrSwitchCaseStmts)[ID] == 0 &&
+ "Already have a SwitchCase with this ID");
+ (*CurrSwitchCaseStmts)[ID] = SC;
}
/// \brief Retrieve the switch-case statement with the given ID.
SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) {
- assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID");
- return SwitchCaseStmts[ID];
+ assert((*CurrSwitchCaseStmts)[ID] != 0 && "No SwitchCase with this ID");
+ return (*CurrSwitchCaseStmts)[ID];
}
void ASTReader::ClearSwitchCaseIDs() {
- SwitchCaseStmts.clear();
+ CurrSwitchCaseStmts->clear();
}
void ASTReader::finishPendingActions() {
@@ -6353,7 +6375,8 @@
DisableValidation(DisableValidation),
DisableStatCache(DisableStatCache),
AllowASTWithCompilerErrors(AllowASTWithCompilerErrors),
- CurrentGeneration(0), NumStatHits(0), NumStatMisses(0),
+ CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts),
+ NumStatHits(0), NumStatMisses(0),
NumSLocEntriesRead(0), TotalNumSLocEntries(0),
NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0),
TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0),
Modified: cfe/branches/tooling/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Serialization/ASTReaderDecl.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/branches/tooling/lib/Serialization/ASTReaderDecl.cpp Tue May 8 03:47:31 2012
@@ -25,6 +25,7 @@
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
+#include "llvm/Support/SaveAndRestore.h"
using namespace clang;
using namespace clang::serialization;
@@ -629,6 +630,10 @@
if (Record[Idx++]) {
// In practice, this won't be executed (since method definitions
// don't occur in header files).
+ // Switch case IDs for this method body.
+ ASTReader::SwitchCaseMapTy SwitchCaseStmtsForObjCMethod;
+ SaveAndRestore<ASTReader::SwitchCaseMapTy *>
+ SCFOM(Reader.CurrSwitchCaseStmts, &SwitchCaseStmtsForObjCMethod);
MD->setBody(Reader.ReadStmt(F));
MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx));
@@ -1085,6 +1090,7 @@
Data.HasPublicFields = Record[Idx++];
Data.HasMutableFields = Record[Idx++];
Data.HasOnlyCMembers = Record[Idx++];
+ Data.HasInClassInitializer = Record[Idx++];
Data.HasTrivialDefaultConstructor = Record[Idx++];
Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Data.DefaultedDefaultConstructorIsConstexpr = Record[Idx++];
Modified: cfe/branches/tooling/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Serialization/ASTReaderStmt.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/branches/tooling/lib/Serialization/ASTReaderStmt.cpp Tue May 8 03:47:31 2012
@@ -1074,7 +1074,8 @@
void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
VisitCallExpr(E);
- E->setOperator((OverloadedOperatorKind)Record[Idx++]);
+ E->Operator = (OverloadedOperatorKind)Record[Idx++];
+ E->Range = Reader.ReadSourceRange(F, Record, Idx);
}
void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
Modified: cfe/branches/tooling/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Serialization/ASTWriter.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/branches/tooling/lib/Serialization/ASTWriter.cpp Tue May 8 03:47:31 2012
@@ -4310,6 +4310,7 @@
Record.push_back(Data.HasPublicFields);
Record.push_back(Data.HasMutableFields);
Record.push_back(Data.HasOnlyCMembers);
+ Record.push_back(Data.HasInClassInitializer);
Record.push_back(Data.HasTrivialDefaultConstructor);
Record.push_back(Data.HasConstexprNonCopyMoveConstructor);
Record.push_back(Data.DefaultedDefaultConstructorIsConstexpr);
Modified: cfe/branches/tooling/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Serialization/ASTWriterDecl.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/branches/tooling/lib/Serialization/ASTWriterDecl.cpp Tue May 8 03:47:31 2012
@@ -1054,7 +1054,7 @@
VisitRedeclarableTemplateDecl(D);
if (D->isFirstDeclaration()) {
- typedef llvm::FoldingSet<ClassTemplateSpecializationDecl> CTSDSetTy;
+ typedef llvm::FoldingSetVector<ClassTemplateSpecializationDecl> CTSDSetTy;
CTSDSetTy &CTSDSet = D->getSpecializations();
Record.push_back(CTSDSet.size());
for (CTSDSetTy::iterator I=CTSDSet.begin(), E = CTSDSet.end(); I!=E; ++I) {
@@ -1062,7 +1062,8 @@
Writer.AddDeclRef(&*I, Record);
}
- typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> CTPSDSetTy;
+ typedef llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
+ CTPSDSetTy;
CTPSDSetTy &CTPSDSet = D->getPartialSpecializations();
Record.push_back(CTPSDSet.size());
for (CTPSDSetTy::iterator I=CTPSDSet.begin(), E=CTPSDSet.end(); I!=E; ++I) {
@@ -1146,7 +1147,7 @@
// Write the function specialization declarations.
Record.push_back(D->getSpecializations().size());
- for (llvm::FoldingSet<FunctionTemplateSpecializationInfo>::iterator
+ for (llvm::FoldingSetVector<FunctionTemplateSpecializationInfo>::iterator
I = D->getSpecializations().begin(),
E = D->getSpecializations().end() ; I != E; ++I) {
assert(I->Function->isCanonicalDecl() &&
Modified: cfe/branches/tooling/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Serialization/ASTWriterStmt.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/branches/tooling/lib/Serialization/ASTWriterStmt.cpp Tue May 8 03:47:31 2012
@@ -1045,6 +1045,7 @@
void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
VisitCallExpr(E);
Record.push_back(E->getOperator());
+ Writer.AddSourceRange(E->Range, Record);
Code = serialization::EXPR_CXX_OPERATOR_CALL;
}
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Tue May 8 03:47:31 2012
@@ -901,9 +901,10 @@
// If the size is zero, there won't be any actual memory access, so
// just bind the return value to the destination buffer and return.
- if (stateZeroSize) {
+ if (stateZeroSize && !stateNonZeroSize) {
stateZeroSize = stateZeroSize->BindExpr(CE, LCtx, destVal);
C.addTransition(stateZeroSize);
+ return;
}
// If the size can be nonzero, we have to check the other arguments.
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp Tue May 8 03:47:31 2012
@@ -144,9 +144,9 @@
assert(RD && "Referred record has no definition");
for (RecordDecl::field_iterator I =
RD->field_begin(), E = RD->field_end(); I!=E; ++I) {
- const FieldRegion *FR = MrMgr.getFieldRegion(*I, R);
- FieldChain.push_back(*I);
- T = (*I)->getType();
+ const FieldRegion *FR = MrMgr.getFieldRegion(&*I, R);
+ FieldChain.push_back(&*I);
+ T = I->getType();
if (T->getAsStructureType()) {
if (Find(FR))
return true;
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp Tue May 8 03:47:31 2012
@@ -114,7 +114,7 @@
for (ObjCInterfaceDecl::ivar_iterator I=ID->ivar_begin(), E=ID->ivar_end();
I!=E; ++I) {
- ObjCIvarDecl *ID = *I;
+ ObjCIvarDecl *ID = &*I;
QualType T = ID->getType();
if (!T->isObjCObjectPointerType() ||
@@ -215,10 +215,10 @@
E = D->propimpl_end(); I!=E; ++I) {
// We can only check the synthesized properties
- if ((*I)->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize)
+ if (I->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize)
continue;
- ObjCIvarDecl *ID = (*I)->getPropertyIvarDecl();
+ ObjCIvarDecl *ID = I->getPropertyIvarDecl();
if (!ID)
continue;
@@ -226,7 +226,7 @@
if (!T->isObjCObjectPointerType()) // Skip non-pointer ivars
continue;
- const ObjCPropertyDecl *PD = (*I)->getPropertyDecl();
+ const ObjCPropertyDecl *PD = I->getPropertyDecl();
if (!PD)
continue;
@@ -261,7 +261,7 @@
}
PathDiagnosticLocation SDLoc =
- PathDiagnosticLocation::createBegin((*I), BR.getSourceManager());
+ PathDiagnosticLocation::createBegin(&*I, BR.getSourceManager());
BR.EmitBasicReport(MD, name, categories::CoreFoundationObjectiveC,
os.str(), SDLoc);
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/Checkers.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/Checkers.td?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/Checkers.td Tue May 8 03:47:31 2012
@@ -283,6 +283,10 @@
HelpText<"Check for memory leaks, double free, and use-after-free problems.">,
DescFile<"MallocChecker.cpp">;
+def MallocSizeofChecker : Checker<"MallocSizeof">,
+ HelpText<"Check for dubious malloc arguments involving sizeof">,
+ DescFile<"MallocSizeofChecker.cpp">;
+
} // end "unix"
let ParentPackage = UnixExperimental in {
@@ -295,10 +299,6 @@
HelpText<"Check for memory leaks, double free, and use-after-free problems. Assumes that all user-defined functions which might free a pointer are annotated.">,
DescFile<"MallocChecker.cpp">;
-def MallocSizeofChecker : Checker<"MallocSizeof">,
- HelpText<"Check for dubious malloc arguments involving sizeof">,
- DescFile<"MallocSizeofChecker.cpp">;
-
def PthreadLockChecker : Checker<"PthreadLock">,
HelpText<"Simple lock -> unlock checker">,
DescFile<"PthreadLockChecker.cpp">;
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp Tue May 8 03:47:31 2012
@@ -231,7 +231,7 @@
for (RecordDecl::field_iterator I = R->field_begin(), E = R->field_end();
I != E; ++I) {
ASTFieldVisitor walker(R, BR);
- walker.Visit(*I);
+ walker.Visit(&*I);
}
}
@@ -247,7 +247,7 @@
const RecordDecl *RD = RT->getDecl()->getDefinition();
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
I != E; ++I)
- Visit(*I);
+ Visit(&*I);
}
FieldChain.pop_back();
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Tue May 8 03:47:31 2012
@@ -137,6 +137,9 @@
return true;
}
+ void printState(raw_ostream &Out, ProgramStateRef State,
+ const char *NL, const char *Sep) const;
+
private:
void initIdentifierInfo(ASTContext &C) const;
@@ -1118,7 +1121,11 @@
// To test (3), generate a new state with the binding added. If it is
// the same state, then it escapes (since the store cannot represent
// the binding).
- escapes = (state == (state->bindLoc(*regionLoc, val)));
+ // Do this only if we know that the store is not supposed to generate the
+ // same state.
+ SVal StoredVal = state->getSVal(regionLoc->getRegion());
+ if (StoredVal != val)
+ escapes = (state == (state->bindLoc(*regionLoc, val)));
}
if (!escapes) {
// Case 4: We do not currently model what happens when a symbol is
@@ -1278,6 +1285,11 @@
if (FName.startswith("NS") && (FName.find("Insert") != StringRef::npos))
return false;
+ // If the call has a callback as an argument, assume the memory
+ // can be freed.
+ if (Call->hasNonZeroCallbackArg())
+ return false;
+
// Otherwise, assume that the function does not free memory.
// Most system calls, do not free the memory.
return true;
@@ -1305,6 +1317,11 @@
return false;
}
+ // If the call has a callback as an argument, assume the memory
+ // can be freed.
+ if (Call->hasNonZeroCallbackArg())
+ return false;
+
// Otherwise, assume that the function does not free memory.
// Most system calls, do not free the memory.
return true;
@@ -1452,6 +1469,14 @@
return new PathDiagnosticEventPiece(Pos, Msg, true, StackHint);
}
+void MallocChecker::printState(raw_ostream &Out, ProgramStateRef State,
+ const char *NL, const char *Sep) const {
+
+ RegionStateTy RS = State->get<RegionState>();
+
+ if (!RS.isEmpty())
+ Out << "Has Malloc data" << NL;
+}
#define REGISTER_CHECKER(name) \
void ento::register##name(CheckerManager &mgr) {\
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp Tue May 8 03:47:31 2012
@@ -139,6 +139,29 @@
}
};
+// Determine if the pointee and sizeof types are compatible. Here
+// we ignore constness of pointer types.
+static bool typesCompatible(ASTContext &C, QualType A, QualType B) {
+ while (true) {
+ A = A.getCanonicalType();
+ B = B.getCanonicalType();
+
+ if (A.getTypePtr() == B.getTypePtr())
+ return true;
+
+ if (const PointerType *ptrA = A->getAs<PointerType>())
+ if (const PointerType *ptrB = B->getAs<PointerType>()) {
+ A = ptrA->getPointeeType();
+ B = ptrB->getPointeeType();
+ continue;
+ }
+
+ break;
+ }
+
+ return false;
+}
+
class MallocSizeofChecker : public Checker<check::ASTCodeBody> {
public:
void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
@@ -166,7 +189,7 @@
continue;
QualType SizeofType = SFinder.Sizeofs[0]->getTypeOfArgument();
- if (!BR.getContext().hasSameUnqualifiedType(PointeeType, SizeofType)) {
+ if (!typesCompatible(BR.getContext(), PointeeType, SizeofType)) {
const TypeSourceInfo *TSI = 0;
if (i->CastedExprParent.is<const VarDecl *>()) {
TSI =
@@ -180,9 +203,8 @@
OS << "Result of '"
<< i->AllocCall->getDirectCallee()->getIdentifier()->getName()
- << "' is converted to type '"
- << CastedType.getAsString() << "', whose pointee type '"
- << PointeeType.getAsString() << "' is incompatible with "
+ << "' is converted to a pointer of type '"
+ << PointeeType.getAsString() << "', which is incompatible with "
<< "sizeof operand type '" << SizeofType.getAsString() << "'";
llvm::SmallVector<SourceRange, 4> Ranges;
Ranges.push_back(i->AllocCall->getCallee()->getSourceRange());
@@ -194,7 +216,7 @@
PathDiagnosticLocation::createBegin(i->AllocCall->getCallee(),
BR.getSourceManager(), ADC);
- BR.EmitBasicReport(D, "allocator sizeof operand mismatch",
+ BR.EmitBasicReport(D, "Allocator sizeof operand mismatch",
categories::UnixAPI,
OS.str(),
L, Ranges.data(), Ranges.size());
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp Tue May 8 03:47:31 2012
@@ -76,7 +76,7 @@
// to an ivar.
for (ObjCImplementationDecl::propimpl_iterator I = ID->propimpl_begin(),
E = ID->propimpl_end(); I!=E; ++I)
- Scan(M, *I);
+ Scan(M, &*I);
// Scan the associated categories as well.
for (const ObjCCategoryDecl *CD =
@@ -109,7 +109,7 @@
for (ObjCInterfaceDecl::ivar_iterator I=ID->ivar_begin(),
E=ID->ivar_end(); I!=E; ++I) {
- const ObjCIvarDecl *ID = *I;
+ const ObjCIvarDecl *ID = &*I;
// Ignore ivars that...
// (a) aren't private
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Tue May 8 03:47:31 2012
@@ -648,6 +648,10 @@
return getPersistentSummary(Summ);
}
+ const RetainSummary *getDoNothingSummary() {
+ return getPersistentSummary(RetEffect::MakeNoRet(), DoNothing, DoNothing);
+ }
+
const RetainSummary *getDefaultSummary() {
return getPersistentSummary(RetEffect::MakeNoRet(),
DoNothing, MayEscape);
@@ -739,7 +743,8 @@
InitializeMethodSummaries();
}
- const RetainSummary *getSummary(const FunctionDecl *FD);
+ const RetainSummary *getSummary(const FunctionDecl *FD,
+ const CallOrObjCMessage *CME = 0);
const RetainSummary *getMethodSummary(Selector S, IdentifierInfo *ClsName,
const ObjCInterfaceDecl *ID,
@@ -886,7 +891,9 @@
return FName.find("MakeCollectable") != StringRef::npos;
}
-const RetainSummary * RetainSummaryManager::getSummary(const FunctionDecl *FD) {
+const RetainSummary *
+RetainSummaryManager::getSummary(const FunctionDecl *FD,
+ const CallOrObjCMessage *CME) {
// Look up a summary in our cache of FunctionDecls -> Summaries.
FuncSummariesTy::iterator I = FuncSummaries.find(FD);
if (I != FuncSummaries.end())
@@ -941,6 +948,7 @@
} else if (FName == "IOBSDNameMatching" ||
FName == "IOServiceMatching" ||
FName == "IOServiceNameMatching" ||
+ FName == "IORegistryEntrySearchCFProperty" ||
FName == "IORegistryEntryIDMatching" ||
FName == "IOOpenFirmwarePathMatching") {
// Part of <rdar://problem/6961230>. (IOKit)
@@ -993,6 +1001,8 @@
// libdispatch finalizers.
ScratchArgs = AF.add(ScratchArgs, 1, StopTracking);
S = getPersistentSummary(RetEffect::MakeNoRet(), DoNothing, DoNothing);
+ } else if (FName.startswith("NSLog")) {
+ S = getDoNothingSummary();
} else if (FName.startswith("NS") &&
(FName.find("Insert") != StringRef::npos)) {
// Whitelist NSXXInsertXX, for example NSMapInsertIfAbsent, since they can
@@ -1000,6 +1010,9 @@
ScratchArgs = AF.add(ScratchArgs, 1, StopTracking);
ScratchArgs = AF.add(ScratchArgs, 2, StopTracking);
S = getPersistentSummary(RetEffect::MakeNoRet(), DoNothing, DoNothing);
+ } else if (CME && CME->hasNonZeroCallbackArg()) {
+ // Allow objects to escape through callbacks. radar://10973977
+ S = getPersistentStopSummary();
}
// Did we get a summary?
@@ -2632,10 +2645,13 @@
if (dyn_cast_or_null<BlockDataRegion>(L.getAsRegion())) {
Summ = Summaries.getPersistentStopSummary();
} else if (const FunctionDecl *FD = L.getAsFunctionDecl()) {
- Summ = Summaries.getSummary(FD);
+ CallOrObjCMessage CME(CE, state, C.getLocationContext());
+ Summ = Summaries.getSummary(FD, &CME);
} else if (const CXXMemberCallExpr *me = dyn_cast<CXXMemberCallExpr>(CE)) {
- if (const CXXMethodDecl *MD = me->getMethodDecl())
- Summ = Summaries.getSummary(MD);
+ if (const CXXMethodDecl *MD = me->getMethodDecl()) {
+ CallOrObjCMessage CME(CE, state, C.getLocationContext());
+ Summ = Summaries.getSummary(MD, &CME);
+ }
}
if (!Summ)
@@ -2651,13 +2667,14 @@
return;
RetainSummaryManager &Summaries = getSummaryManager(C);
- const RetainSummary *Summ = Summaries.getSummary(Ctor);
+ ProgramStateRef state = C.getState();
+ CallOrObjCMessage CME(CE, state, C.getLocationContext());
+ const RetainSummary *Summ = Summaries.getSummary(Ctor, &CME);
// If we didn't get a summary, this constructor doesn't affect retain counts.
if (!Summ)
return;
- ProgramStateRef state = C.getState();
checkSummary(*Summ, CallOrObjCMessage(CE, state, C.getLocationContext()), C);
}
@@ -3249,7 +3266,7 @@
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CD)) {
if (!isa<CXXMethodDecl>(FD))
- if (const RetainSummary *Summ = Summaries.getSummary(FD))
+ if (const RetainSummary *Summ = Summaries.getSummary(FD, 0))
checkReturnWithRetEffect(S, C, Pred, Summ->getRetEffect(), X,
Sym, state);
}
@@ -3346,7 +3363,11 @@
// To test (3), generate a new state with the binding added. If it is
// the same state, then it escapes (since the store cannot represent
// the binding).
- escapes = (state == (state->bindLoc(*regionLoc, val)));
+ // Do this only if we know that the store is not supposed to generate the
+ // same state.
+ SVal StoredVal = state->getSVal(regionLoc->getRegion());
+ if (StoredVal != val)
+ escapes = (state == (state->bindLoc(*regionLoc, val)));
}
if (!escapes) {
// Case 4: We do not currently model what happens when a symbol is
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/BasicConstraintManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/BasicConstraintManager.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/BasicConstraintManager.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/BasicConstraintManager.cpp Tue May 8 03:47:31 2012
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "SimpleConstraintManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "llvm/Support/raw_ostream.h"
@@ -53,18 +54,25 @@
ProgramState::IntSetTy::Factory ISetFactory;
public:
BasicConstraintManager(ProgramStateManager &statemgr, SubEngine &subengine)
- : SimpleConstraintManager(subengine),
+ : SimpleConstraintManager(subengine, statemgr.getBasicVals()),
ISetFactory(statemgr.getAllocator()) {}
- ProgramStateRef assumeSymNE(ProgramStateRef state,
- SymbolRef sym,
- const llvm::APSInt& V,
- const llvm::APSInt& Adjustment);
+ ProgramStateRef assumeSymEquality(ProgramStateRef State, SymbolRef Sym,
+ const llvm::APSInt &V,
+ const llvm::APSInt &Adjustment,
+ bool Assumption);
- ProgramStateRef assumeSymEQ(ProgramStateRef state,
- SymbolRef sym,
- const llvm::APSInt& V,
- const llvm::APSInt& Adjustment);
+ ProgramStateRef assumeSymNE(ProgramStateRef State, SymbolRef Sym,
+ const llvm::APSInt &V,
+ const llvm::APSInt &Adjustment) {
+ return assumeSymEquality(State, Sym, V, Adjustment, false);
+ }
+
+ ProgramStateRef assumeSymEQ(ProgramStateRef State, SymbolRef Sym,
+ const llvm::APSInt &V,
+ const llvm::APSInt &Adjustment) {
+ return assumeSymEquality(State, Sym, V, Adjustment, true);
+ }
ProgramStateRef assumeSymLT(ProgramStateRef state,
SymbolRef sym,
@@ -108,6 +116,9 @@
ProgramStateRef removeDeadBindings(ProgramStateRef state,
SymbolReaper& SymReaper);
+ bool performTest(llvm::APSInt SymVal, llvm::APSInt Adjustment,
+ BinaryOperator::Opcode Op, llvm::APSInt ComparisonVal);
+
void print(ProgramStateRef state,
raw_ostream &Out,
const char* nl,
@@ -122,60 +133,94 @@
return new BasicConstraintManager(statemgr, subengine);
}
-ProgramStateRef
-BasicConstraintManager::assumeSymNE(ProgramStateRef state,
- SymbolRef sym,
- const llvm::APSInt &V,
- const llvm::APSInt &Adjustment) {
- // First, determine if sym == X, where X+Adjustment != V.
- llvm::APSInt Adjusted = V-Adjustment;
- if (const llvm::APSInt* X = getSymVal(state, sym)) {
- bool isFeasible = (*X != Adjusted);
- return isFeasible ? state : NULL;
- }
-
- // Second, determine if sym+Adjustment != V.
- if (isNotEqual(state, sym, Adjusted))
- return state;
+// FIXME: This is a more general utility and should live somewhere else.
+bool BasicConstraintManager::performTest(llvm::APSInt SymVal,
+ llvm::APSInt Adjustment,
+ BinaryOperator::Opcode Op,
+ llvm::APSInt ComparisonVal) {
+ APSIntType Type(Adjustment);
+ Type.apply(SymVal);
+ Type.apply(ComparisonVal);
+ SymVal += Adjustment;
+
+ assert(BinaryOperator::isComparisonOp(Op));
+ BasicValueFactory &BVF = getBasicVals();
+ const llvm::APSInt *Result = BVF.evalAPSInt(Op, SymVal, ComparisonVal);
+ assert(Result && "Comparisons should always have valid results.");
+
+ return Result->getBoolValue();
+}
+
+ProgramStateRef
+BasicConstraintManager::assumeSymEquality(ProgramStateRef State, SymbolRef Sym,
+ const llvm::APSInt &V,
+ const llvm::APSInt &Adjustment,
+ bool Assumption) {
+ // Before we do any real work, see if the value can even show up.
+ APSIntType AdjustmentType(Adjustment);
+ if (AdjustmentType.testInRange(V) != APSIntType::RTR_Within)
+ return Assumption ? NULL : State;
+
+ // Get the symbol type.
+ BasicValueFactory &BVF = getBasicVals();
+ ASTContext &Ctx = BVF.getContext();
+ APSIntType SymbolType = BVF.getAPSIntType(Sym->getType(Ctx));
+
+ // First, see if the adjusted value is within range for the symbol.
+ llvm::APSInt Adjusted = AdjustmentType.convert(V) - Adjustment;
+ if (SymbolType.testInRange(Adjusted) != APSIntType::RTR_Within)
+ return Assumption ? NULL : State;
+
+ // Now we can do things properly in the symbol space.
+ SymbolType.apply(Adjusted);
+
+ // Second, determine if sym == X, where X+Adjustment != V.
+ if (const llvm::APSInt *X = getSymVal(State, Sym)) {
+ bool IsFeasible = (*X == Adjusted);
+ return (IsFeasible == Assumption) ? State : NULL;
+ }
+
+ // Third, determine if we already know sym+Adjustment != V.
+ if (isNotEqual(State, Sym, Adjusted))
+ return Assumption ? NULL : State;
// If we reach here, sym is not a constant and we don't know if it is != V.
- // Make that assumption.
- return AddNE(state, sym, Adjusted);
-}
-
-ProgramStateRef
-BasicConstraintManager::assumeSymEQ(ProgramStateRef state,
- SymbolRef sym,
- const llvm::APSInt &V,
- const llvm::APSInt &Adjustment) {
- // First, determine if sym == X, where X+Adjustment != V.
- llvm::APSInt Adjusted = V-Adjustment;
- if (const llvm::APSInt* X = getSymVal(state, sym)) {
- bool isFeasible = (*X == Adjusted);
- return isFeasible ? state : NULL;
- }
-
- // Second, determine if sym+Adjustment != V.
- if (isNotEqual(state, sym, Adjusted))
- return NULL;
-
- // If we reach here, sym is not a constant and we don't know if it is == V.
- // Make that assumption.
- return AddEQ(state, sym, Adjusted);
+ // Make the correct assumption.
+ if (Assumption)
+ return AddEQ(State, Sym, Adjusted);
+ else
+ return AddNE(State, Sym, Adjusted);
}
// The logic for these will be handled in another ConstraintManager.
+// Approximate it here anyway by handling some edge cases.
ProgramStateRef
BasicConstraintManager::assumeSymLT(ProgramStateRef state,
SymbolRef sym,
const llvm::APSInt &V,
const llvm::APSInt &Adjustment) {
- // Is 'V' the smallest possible value?
- if (V == llvm::APSInt::getMinValue(V.getBitWidth(), V.isUnsigned())) {
+ APSIntType ComparisonType(V), AdjustmentType(Adjustment);
+
+ // Is 'V' out of range above the type?
+ llvm::APSInt Max = AdjustmentType.getMaxValue();
+ if (V > ComparisonType.convert(Max)) {
+ // This path is trivially feasible.
+ return state;
+ }
+
+ // Is 'V' the smallest possible value, or out of range below the type?
+ llvm::APSInt Min = AdjustmentType.getMinValue();
+ if (V <= ComparisonType.convert(Min)) {
// sym cannot be any value less than 'V'. This path is infeasible.
return NULL;
}
+ // Reject a path if the value of sym is a constant X and !(X+Adj < V).
+ if (const llvm::APSInt *X = getSymVal(state, sym)) {
+ bool isFeasible = performTest(*X, Adjustment, BO_LT, V);
+ return isFeasible ? state : NULL;
+ }
+
// FIXME: For now have assuming x < y be the same as assuming sym != V;
return assumeSymNE(state, sym, V, Adjustment);
}
@@ -185,12 +230,28 @@
SymbolRef sym,
const llvm::APSInt &V,
const llvm::APSInt &Adjustment) {
- // Is 'V' the largest possible value?
- if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isUnsigned())) {
+ APSIntType ComparisonType(V), AdjustmentType(Adjustment);
+
+ // Is 'V' the largest possible value, or out of range above the type?
+ llvm::APSInt Max = AdjustmentType.getMaxValue();
+ if (V >= ComparisonType.convert(Max)) {
// sym cannot be any value greater than 'V'. This path is infeasible.
return NULL;
}
+ // Is 'V' out of range below the type?
+ llvm::APSInt Min = AdjustmentType.getMinValue();
+ if (V < ComparisonType.convert(Min)) {
+ // This path is trivially feasible.
+ return state;
+ }
+
+ // Reject a path if the value of sym is a constant X and !(X+Adj > V).
+ if (const llvm::APSInt *X = getSymVal(state, sym)) {
+ bool isFeasible = performTest(*X, Adjustment, BO_GT, V);
+ return isFeasible ? state : NULL;
+ }
+
// FIXME: For now have assuming x > y be the same as assuming sym != V;
return assumeSymNE(state, sym, V, Adjustment);
}
@@ -200,25 +261,33 @@
SymbolRef sym,
const llvm::APSInt &V,
const llvm::APSInt &Adjustment) {
- // Reject a path if the value of sym is a constant X and !(X+Adj >= V).
- if (const llvm::APSInt *X = getSymVal(state, sym)) {
- bool isFeasible = (*X >= V-Adjustment);
- return isFeasible ? state : NULL;
- }
+ APSIntType ComparisonType(V), AdjustmentType(Adjustment);
- // Sym is not a constant, but it is worth looking to see if V is the
- // maximum integer value.
- if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isUnsigned())) {
- llvm::APSInt Adjusted = V-Adjustment;
-
- // If we know that sym != V (after adjustment), then this condition
- // is infeasible since there is no other value greater than V.
- bool isFeasible = !isNotEqual(state, sym, Adjusted);
+ // Is 'V' the largest possible value, or out of range above the type?
+ llvm::APSInt Max = AdjustmentType.getMaxValue();
+ ComparisonType.apply(Max);
- // If the path is still feasible then as a consequence we know that
+ if (V > Max) {
+ // sym cannot be any value greater than 'V'. This path is infeasible.
+ return NULL;
+ } else if (V == Max) {
+ // If the path is feasible then as a consequence we know that
// 'sym+Adjustment == V' because there are no larger values.
// Add this constraint.
- return isFeasible ? AddEQ(state, sym, Adjusted) : NULL;
+ return assumeSymEQ(state, sym, V, Adjustment);
+ }
+
+ // Is 'V' out of range below the type?
+ llvm::APSInt Min = AdjustmentType.getMinValue();
+ if (V < ComparisonType.convert(Min)) {
+ // This path is trivially feasible.
+ return state;
+ }
+
+ // Reject a path if the value of sym is a constant X and !(X+Adj >= V).
+ if (const llvm::APSInt *X = getSymVal(state, sym)) {
+ bool isFeasible = performTest(*X, Adjustment, BO_GE, V);
+ return isFeasible ? state : NULL;
}
return state;
@@ -229,25 +298,33 @@
SymbolRef sym,
const llvm::APSInt &V,
const llvm::APSInt &Adjustment) {
- // Reject a path if the value of sym is a constant X and !(X+Adj <= V).
- if (const llvm::APSInt* X = getSymVal(state, sym)) {
- bool isFeasible = (*X <= V-Adjustment);
- return isFeasible ? state : NULL;
+ APSIntType ComparisonType(V), AdjustmentType(Adjustment);
+
+ // Is 'V' out of range above the type?
+ llvm::APSInt Max = AdjustmentType.getMaxValue();
+ if (V > ComparisonType.convert(Max)) {
+ // This path is trivially feasible.
+ return state;
}
- // Sym is not a constant, but it is worth looking to see if V is the
- // minimum integer value.
- if (V == llvm::APSInt::getMinValue(V.getBitWidth(), V.isUnsigned())) {
- llvm::APSInt Adjusted = V-Adjustment;
-
- // If we know that sym != V (after adjustment), then this condition
- // is infeasible since there is no other value less than V.
- bool isFeasible = !isNotEqual(state, sym, Adjusted);
+ // Is 'V' the smallest possible value, or out of range below the type?
+ llvm::APSInt Min = AdjustmentType.getMinValue();
+ ComparisonType.apply(Min);
- // If the path is still feasible then as a consequence we know that
+ if (V < Min) {
+ // sym cannot be any value less than 'V'. This path is infeasible.
+ return NULL;
+ } else if (V == Min) {
+ // If the path is feasible then as a consequence we know that
// 'sym+Adjustment == V' because there are no smaller values.
// Add this constraint.
- return isFeasible ? AddEQ(state, sym, Adjusted) : NULL;
+ return assumeSymEQ(state, sym, V, Adjustment);
+ }
+
+ // Reject a path if the value of sym is a constant X and !(X+Adj >= V).
+ if (const llvm::APSInt *X = getSymVal(state, sym)) {
+ bool isFeasible = performTest(*X, Adjustment, BO_LE, V);
+ return isFeasible ? state : NULL;
}
return state;
@@ -256,8 +333,10 @@
ProgramStateRef BasicConstraintManager::AddEQ(ProgramStateRef state,
SymbolRef sym,
const llvm::APSInt& V) {
- // Create a new state with the old binding replaced.
- return state->set<ConstEq>(sym, &state->getBasicVals().getValue(V));
+ // Now that we have an actual value, we can throw out the NE-set.
+ // Create a new state with the old bindings replaced.
+ state = state->remove<ConstNotEq>(sym);
+ return state->set<ConstEq>(sym, &getBasicVals().getValue(V));
}
ProgramStateRef BasicConstraintManager::AddNE(ProgramStateRef state,
@@ -269,7 +348,7 @@
ProgramState::IntSetTy S = T ? *T : ISetFactory.getEmptySet();
// Now add V to the NE set.
- S = ISetFactory.add(S, &state->getBasicVals().getValue(V));
+ S = ISetFactory.add(S, &getBasicVals().getValue(V));
// Create a new state with the old binding replaced.
return state->set<ConstNotEq>(sym, S);
@@ -289,7 +368,7 @@
const ConstNotEqTy::data_type* T = state->get<ConstNotEq>(sym);
// See if V is present in the NE-set.
- return T ? T->contains(&state->getBasicVals().getValue(V)) : false;
+ return T ? T->contains(&getBasicVals().getValue(V)) : false;
}
bool BasicConstraintManager::isEqual(ProgramStateRef state,
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporter.cpp Tue May 8 03:47:31 2012
@@ -1051,6 +1051,79 @@
CLocs.push_back(L);
}
+// Cone-of-influence: support the reverse propagation of "interesting" symbols
+// and values by tracing interesting calculations backwards through evaluated
+// expressions along a path. This is probably overly complicated, but the idea
+// is that if an expression computed an "interesting" value, the child
+// expressions are are also likely to be "interesting" as well (which then
+// propagates to the values they in turn compute). This reverse propagation
+// is needed to track interesting correlations across function call boundaries,
+// where formal arguments bind to actual arguments, etc. This is also needed
+// because the constraint solver sometimes simplifies certain symbolic values
+// into constants when appropriate, and this complicates reasoning about
+// interesting values.
+typedef llvm::DenseSet<const Expr *> InterestingExprs;
+
+static void reversePropagateIntererstingSymbols(BugReport &R,
+ InterestingExprs &IE,
+ const ProgramState *State,
+ const Expr *Ex,
+ const LocationContext *LCtx) {
+ SVal V = State->getSVal(Ex, LCtx);
+ if (!(R.isInteresting(V) || IE.count(Ex)))
+ return;
+
+ switch (Ex->getStmtClass()) {
+ default:
+ if (!isa<CastExpr>(Ex))
+ break;
+ // Fall through.
+ case Stmt::BinaryOperatorClass:
+ case Stmt::UnaryOperatorClass: {
+ for (Stmt::const_child_iterator CI = Ex->child_begin(),
+ CE = Ex->child_end();
+ CI != CE; ++CI) {
+ if (const Expr *child = dyn_cast_or_null<Expr>(*CI)) {
+ IE.insert(child);
+ SVal ChildV = State->getSVal(child, LCtx);
+ R.markInteresting(ChildV);
+ }
+ break;
+ }
+ }
+ }
+
+ R.markInteresting(V);
+}
+
+static void reversePropagateInterestingSymbols(BugReport &R,
+ InterestingExprs &IE,
+ const ProgramState *State,
+ const LocationContext *CalleeCtx,
+ const LocationContext *CallerCtx)
+{
+ // FIXME: Handle CXXConstructExpr.
+ // FIXME: Handle calls to blocks.
+ const StackFrameContext *Callee = CalleeCtx->getCurrentStackFrame();
+ const Stmt *CallSite = Callee->getCallSite();
+ if (const CallExpr *CE = dyn_cast<CallExpr>(CallSite)) {
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CalleeCtx->getDecl())) {
+ FunctionDecl::param_const_iterator PI = FD->param_begin(),
+ PE = FD->param_end();
+ CallExpr::const_arg_iterator AI = CE->arg_begin(), AE = CE->arg_end();
+ for (; AI != AE && PI != PE; ++AI, ++PI) {
+ if (const Expr *ArgE = *AI) {
+ if (const ParmVarDecl *PD = *PI) {
+ Loc LV = State->getLValue(PD, CalleeCtx);
+ if (R.isInteresting(LV) || R.isInteresting(State->getRawSVal(LV)))
+ IE.insert(ArgE);
+ }
+ }
+ }
+ }
+ }
+}
+
static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD,
PathDiagnosticBuilder &PDB,
const ExplodedNode *N,
@@ -1058,6 +1131,7 @@
EdgeBuilder EB(PD, PDB);
const SourceManager& SM = PDB.getSourceManager();
StackDiagVector CallStack;
+ InterestingExprs IE;
const ExplodedNode *NextNode = N->pred_empty() ? NULL : *(N->pred_begin());
while (NextNode) {
@@ -1066,6 +1140,13 @@
ProgramPoint P = N->getLocation();
do {
+ if (const PostStmt *PS = dyn_cast<PostStmt>(&P)) {
+ if (const Expr *Ex = PS->getStmtAs<Expr>())
+ reversePropagateIntererstingSymbols(*PDB.getBugReport(), IE,
+ N->getState().getPtr(), Ex,
+ N->getLocationContext());
+ }
+
if (const CallExitEnd *CE = dyn_cast<CallExitEnd>(&P)) {
const StackFrameContext *LCtx =
CE->getLocationContext()->getCurrentStackFrame();
@@ -1127,7 +1208,19 @@
PDB.LC = N->getLocationContext();
// Block edges.
- if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
+ if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
+ // Does this represent entering a call? If so, look at propagating
+ // interesting symbols across call boundaries.
+ if (NextNode) {
+ const LocationContext *CallerCtx = NextNode->getLocationContext();
+ const LocationContext *CalleeCtx = PDB.LC;
+ if (CallerCtx != CalleeCtx) {
+ reversePropagateInterestingSymbols(*PDB.getBugReport(), IE,
+ N->getState().getPtr(),
+ CalleeCtx, CallerCtx);
+ }
+ }
+
const CFGBlock &Blk = *BE->getSrc();
const Stmt *Term = Blk.getTerminator();
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue May 8 03:47:31 2012
@@ -34,15 +34,23 @@
// a[0], p->f, *p
const Stmt *S = N->getLocationAs<PostStmt>()->getStmt();
- if (const UnaryOperator *U = dyn_cast<UnaryOperator>(S)) {
- if (U->getOpcode() == UO_Deref)
- return U->getSubExpr()->IgnoreParenCasts();
- }
- else if (const MemberExpr *ME = dyn_cast<MemberExpr>(S)) {
- return ME->getBase()->IgnoreParenCasts();
- }
- else if (const ArraySubscriptExpr *AE = dyn_cast<ArraySubscriptExpr>(S)) {
- return AE->getBase();
+ while (true) {
+ if (const BinaryOperator *B = dyn_cast<BinaryOperator>(S)) {
+ assert(B->isAssignmentOp());
+ S = B->getLHS()->IgnoreParenCasts();
+ continue;
+ }
+ else if (const UnaryOperator *U = dyn_cast<UnaryOperator>(S)) {
+ if (U->getOpcode() == UO_Deref)
+ return U->getSubExpr()->IgnoreParenCasts();
+ }
+ else if (const MemberExpr *ME = dyn_cast<MemberExpr>(S)) {
+ return ME->getBase()->IgnoreParenCasts();
+ }
+ else if (const ArraySubscriptExpr *AE = dyn_cast<ArraySubscriptExpr>(S)) {
+ return AE->getBase();
+ }
+ break;
}
return NULL;
@@ -320,7 +328,7 @@
StateMgr.getRegionManager().getVarRegion(VD, N->getLocationContext());
// What did we load?
- SVal V = state->getSVal(loc::MemRegionVal(R));
+ SVal V = state->getRawSVal(loc::MemRegionVal(R));
report->markInteresting(R);
report->markInteresting(V);
return new FindLastStoreBRVisitor(V, R);
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/CMakeLists.txt?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/CMakeLists.txt (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/CMakeLists.txt Tue May 8 03:47:31 2012
@@ -4,6 +4,7 @@
add_clang_library(clangStaticAnalyzerCore
AnalysisManager.cpp
+ APSIntType.cpp
BasicConstraintManager.cpp
BasicValueFactory.cpp
BlockCounter.cpp
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/Environment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/Environment.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/Environment.cpp Tue May 8 03:47:31 2012
@@ -71,6 +71,11 @@
else
return svalBuilder.makeBoolVal(cast<CXXBoolLiteralExpr>(E));
}
+ case Stmt::CXXScalarValueInitExprClass:
+ case Stmt::ImplicitValueInitExprClass: {
+ QualType Ty = cast<Expr>(E)->getType();
+ return svalBuilder.makeZeroVal(Ty);
+ }
case Stmt::IntegerLiteralClass: {
// In C++, this expression may have been bound to a temporary object.
SVal const *X = ExprBindings.lookup(EnvironmentEntry(E, LCtx));
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue May 8 03:47:31 2012
@@ -496,7 +496,6 @@
case Stmt::CXXTypeidExprClass:
case Stmt::CXXUuidofExprClass:
case Stmt::CXXUnresolvedConstructExprClass:
- case Stmt::CXXScalarValueInitExprClass:
case Stmt::DependentScopeDeclRefExprClass:
case Stmt::UnaryTypeTraitExprClass:
case Stmt::BinaryTypeTraitExprClass:
@@ -573,15 +572,6 @@
// Implicitly handled by Environment::getSVal().
break;
- case Stmt::ImplicitValueInitExprClass: {
- ProgramStateRef state = Pred->getState();
- QualType ty = cast<ImplicitValueInitExpr>(S)->getType();
- SVal val = svalBuilder.makeZeroVal(ty);
- Bldr.generateNode(S, Pred, state->BindExpr(S, Pred->getLocationContext(),
- val));
- break;
- }
-
case Stmt::ExprWithCleanupsClass:
// Handled due to fully linearised CFG.
break;
@@ -619,6 +609,8 @@
case Stmt::AddrLabelExprClass:
case Stmt::IntegerLiteralClass:
case Stmt::CharacterLiteralClass:
+ case Stmt::ImplicitValueInitExprClass:
+ case Stmt::CXXScalarValueInitExprClass:
case Stmt::CXXBoolLiteralExprClass:
case Stmt::ObjCBoolLiteralExprClass:
case Stmt::FloatingLiteralClass:
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineC.cpp Tue May 8 03:47:31 2012
@@ -58,6 +58,26 @@
if (!B->isAssignmentOp()) {
StmtNodeBuilder Bldr(*it, Tmp2, *currentBuilderContext);
+
+ if (B->isAdditiveOp()) {
+ // If one of the operands is a location, conjure a symbol for the other
+ // one (offset) if it's unknown so that memory arithmetic always
+ // results in an ElementRegion.
+ // TODO: This can be removed after we enable history tracking with
+ // SymSymExpr.
+ unsigned Count = currentBuilderContext->getCurrentBlockCount();
+ if (isa<Loc>(LeftV) &&
+ RHS->getType()->isIntegerType() && RightV.isUnknown()) {
+ RightV = svalBuilder.getConjuredSymbolVal(RHS, LCtx,
+ RHS->getType(), Count);
+ }
+ if (isa<Loc>(RightV) &&
+ LHS->getType()->isIntegerType() && LeftV.isUnknown()) {
+ LeftV = svalBuilder.getConjuredSymbolVal(LHS, LCtx,
+ LHS->getType(), Count);
+ }
+ }
+
// Process non-assignments except commas or short-circuited
// logical expressions (LAnd and LOr).
SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
@@ -162,14 +182,35 @@
ExplodedNodeSet &Dst) {
CanQualType T = getContext().getCanonicalType(BE->getType());
+
+ // Get the value of the block itself.
SVal V = svalBuilder.getBlockPointer(BE->getBlockDecl(), T,
Pred->getLocationContext());
+ ProgramStateRef State = Pred->getState();
+
+ // If we created a new MemRegion for the block, we should explicitly bind
+ // the captured variables.
+ if (const BlockDataRegion *BDR =
+ dyn_cast_or_null<BlockDataRegion>(V.getAsRegion())) {
+
+ BlockDataRegion::referenced_vars_iterator I = BDR->referenced_vars_begin(),
+ E = BDR->referenced_vars_end();
+
+ for (; I != E; ++I) {
+ const MemRegion *capturedR = I.getCapturedRegion();
+ const MemRegion *originalR = I.getOriginalRegion();
+ if (capturedR != originalR) {
+ SVal originalV = State->getSVal(loc::MemRegionVal(originalR));
+ State = State->bindLoc(loc::MemRegionVal(capturedR), originalV);
+ }
+ }
+ }
+
ExplodedNodeSet Tmp;
StmtNodeBuilder Bldr(Pred, Tmp, *currentBuilderContext);
Bldr.generateNode(BE, Pred,
- Pred->getState()->BindExpr(BE, Pred->getLocationContext(),
- V),
+ State->BindExpr(BE, Pred->getLocationContext(), V),
false, 0,
ProgramPoint::PostLValueKind);
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Tue May 8 03:47:31 2012
@@ -323,12 +323,14 @@
// allocators/deallocators upon container construction.
// - NSXXInsertXX, for example NSMapInsertIfAbsent, since they can
// be deallocated by NSMapRemove.
+ // - Any call that has a callback as one of the arguments.
if (FName == "pthread_setspecific" ||
FName == "funopen" ||
FName.endswith("NoCopy") ||
(FName.startswith("NS") &&
(FName.find("Insert") != StringRef::npos)) ||
- Call.isCFCGAllowingEscape(FName))
+ Call.isCFCGAllowingEscape(FName) ||
+ Call.hasNonZeroCallbackArg())
return;
}
@@ -344,6 +346,10 @@
if (const ObjCMethodDecl *MDecl = dyn_cast<ObjCMethodDecl>(CallDecl)) {
assert(MDecl->param_size() <= Call.getNumArgs());
unsigned Idx = 0;
+
+ if (Call.hasNonZeroCallbackArg())
+ return;
+
for (clang::ObjCMethodDecl::param_const_iterator
I = MDecl->param_begin(), E = MDecl->param_end(); I != E; ++I, ++Idx) {
if (isPointerToConst(*I))
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/MemRegion.cpp Tue May 8 03:47:31 2012
@@ -1016,7 +1016,7 @@
unsigned idx = 0;
for (RecordDecl::field_iterator FI = RD->field_begin(),
FE = RD->field_end(); FI != FE; ++FI, ++idx)
- if (FR->getDecl() == *FI)
+ if (FR->getDecl() == &*FI)
break;
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
@@ -1056,26 +1056,37 @@
typedef BumpVector<const MemRegion*> VarVec;
VarVec *BV = (VarVec*) A.Allocate<VarVec>();
new (BV) VarVec(BC, E - I);
+ VarVec *BVOriginal = (VarVec*) A.Allocate<VarVec>();
+ new (BVOriginal) VarVec(BC, E - I);
for ( ; I != E; ++I) {
const VarDecl *VD = *I;
const VarRegion *VR = 0;
+ const VarRegion *OriginalVR = 0;
- if (!VD->getAttr<BlocksAttr>() && VD->hasLocalStorage())
+ if (!VD->getAttr<BlocksAttr>() && VD->hasLocalStorage()) {
VR = MemMgr.getVarRegion(VD, this);
+ OriginalVR = MemMgr.getVarRegion(VD, LC);
+ }
else {
- if (LC)
+ if (LC) {
VR = MemMgr.getVarRegion(VD, LC);
+ OriginalVR = VR;
+ }
else {
VR = MemMgr.getVarRegion(VD, MemMgr.getUnknownRegion());
+ OriginalVR = MemMgr.getVarRegion(VD, LC);
}
}
assert(VR);
+ assert(OriginalVR);
BV->push_back(VR, BC);
+ BVOriginal->push_back(OriginalVR, BC);
}
ReferencedVars = BV;
+ OriginalVars = BVOriginal;
}
BlockDataRegion::referenced_vars_iterator
@@ -1085,8 +1096,14 @@
BumpVector<const MemRegion*> *Vec =
static_cast<BumpVector<const MemRegion*>*>(ReferencedVars);
- return BlockDataRegion::referenced_vars_iterator(Vec == (void*) 0x1 ?
- NULL : Vec->begin());
+ if (Vec == (void*) 0x1)
+ return BlockDataRegion::referenced_vars_iterator(0, 0);
+
+ BumpVector<const MemRegion*> *VecOriginal =
+ static_cast<BumpVector<const MemRegion*>*>(OriginalVars);
+
+ return BlockDataRegion::referenced_vars_iterator(Vec->begin(),
+ VecOriginal->begin());
}
BlockDataRegion::referenced_vars_iterator
@@ -1096,6 +1113,12 @@
BumpVector<const MemRegion*> *Vec =
static_cast<BumpVector<const MemRegion*>*>(ReferencedVars);
- return BlockDataRegion::referenced_vars_iterator(Vec == (void*) 0x1 ?
- NULL : Vec->end());
+ if (Vec == (void*) 0x1)
+ return BlockDataRegion::referenced_vars_iterator(0, 0);
+
+ BumpVector<const MemRegion*> *VecOriginal =
+ static_cast<BumpVector<const MemRegion*>*>(OriginalVars);
+
+ return BlockDataRegion::referenced_vars_iterator(Vec->end(),
+ VecOriginal->end());
}
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/ObjCMessage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/ObjCMessage.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/ObjCMessage.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/ObjCMessage.cpp Tue May 8 03:47:31 2012
@@ -88,3 +88,87 @@
return 0;
}
+bool CallOrObjCMessage::isCallbackArg(unsigned Idx, const Type *T) const {
+ // If the parameter is 0, it's harmless.
+ if (getArgSVal(Idx).isZeroConstant())
+ return false;
+
+ // If a parameter is a block or a callback, assume it can modify pointer.
+ if (T->isBlockPointerType() || T->isFunctionPointerType())
+ return true;
+
+ // Check if a callback is passed inside a struct (for both, struct passed by
+ // reference and by value). Dig just one level into the struct for now.
+ if (const PointerType *PT = dyn_cast<PointerType>(T))
+ T = PT->getPointeeType().getTypePtr();
+
+ if (const RecordType *RT = T->getAsStructureType()) {
+ const RecordDecl *RD = RT->getDecl();
+ for (RecordDecl::field_iterator I = RD->field_begin(),
+ E = RD->field_end(); I != E; ++I ) {
+ const Type *FieldT = I->getType().getTypePtr();
+ if (FieldT->isBlockPointerType() || FieldT->isFunctionPointerType())
+ return true;
+ }
+ }
+ return false;
+}
+
+bool CallOrObjCMessage::hasNonZeroCallbackArg() const {
+ unsigned NumOfArgs = getNumArgs();
+
+ // Process ObjC message first.
+ if (!CallE) {
+ const ObjCMethodDecl *D = Msg.getMethodDecl();
+ unsigned Idx = 0;
+ for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
+ E = D->param_end(); I != E; ++I, ++Idx) {
+ if (NumOfArgs <= Idx)
+ break;
+
+ if (isCallbackArg(Idx, (*I)->getType().getTypePtr()))
+ return true;
+ }
+ return false;
+ }
+
+ // Else, assume we are dealing with a Function call.
+ const FunctionDecl *FD = 0;
+ if (const CXXConstructExpr *Ctor =
+ CallE.dyn_cast<const CXXConstructExpr *>())
+ FD = Ctor->getConstructor();
+
+ const CallExpr * CE = CallE.get<const CallExpr *>();
+ FD = dyn_cast_or_null<FunctionDecl>(CE->getCalleeDecl());
+
+ // If calling using a function pointer, assume the function does not
+ // have a callback. TODO: We could check the types of the arguments here.
+ if (!FD)
+ return false;
+
+ unsigned Idx = 0;
+ for (FunctionDecl::param_const_iterator I = FD->param_begin(),
+ E = FD->param_end(); I != E; ++I, ++Idx) {
+ if (NumOfArgs <= Idx)
+ break;
+
+ if (isCallbackArg(Idx, (*I)->getType().getTypePtr()))
+ return true;
+ }
+ return false;
+}
+
+bool CallOrObjCMessage::isCFCGAllowingEscape(StringRef FName) {
+ if (FName[0] == 'C' && (FName[1] == 'F' || FName[1] == 'G'))
+ if (StrInStrNoCase(FName, "InsertValue") != StringRef::npos||
+ StrInStrNoCase(FName, "AddValue") != StringRef::npos ||
+ StrInStrNoCase(FName, "SetValue") != StringRef::npos ||
+ StrInStrNoCase(FName, "WithData") != StringRef::npos ||
+ StrInStrNoCase(FName, "AppendValue") != StringRef::npos||
+ StrInStrNoCase(FName, "SetAttribute") != StringRef::npos) {
+ return true;
+ }
+ return false;
+}
+
+
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp Tue May 8 03:47:31 2012
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "SimpleConstraintManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "llvm/Support/Debug.h"
@@ -143,6 +144,92 @@
}
}
+ const llvm::APSInt &getMinValue() const {
+ assert(!isEmpty());
+ return ranges.begin()->From();
+ }
+
+ bool pin(llvm::APSInt &Lower, llvm::APSInt &Upper) const {
+ // This function has nine cases, the cartesian product of range-testing
+ // both the upper and lower bounds against the symbol's type.
+ // Each case requires a different pinning operation.
+ // The function returns false if the described range is entirely outside
+ // the range of values for the associated symbol.
+ APSIntType Type(getMinValue());
+ APSIntType::RangeTestResultKind LowerTest = Type.testInRange(Lower);
+ APSIntType::RangeTestResultKind UpperTest = Type.testInRange(Upper);
+
+ switch (LowerTest) {
+ case APSIntType::RTR_Below:
+ switch (UpperTest) {
+ case APSIntType::RTR_Below:
+ // The entire range is outside the symbol's set of possible values.
+ // If this is a conventionally-ordered range, the state is infeasible.
+ if (Lower < Upper)
+ return false;
+
+ // However, if the range wraps around, it spans all possible values.
+ Lower = Type.getMinValue();
+ Upper = Type.getMaxValue();
+ break;
+ case APSIntType::RTR_Within:
+ // The range starts below what's possible but ends within it. Pin.
+ Lower = Type.getMinValue();
+ Type.apply(Upper);
+ break;
+ case APSIntType::RTR_Above:
+ // The range spans all possible values for the symbol. Pin.
+ Lower = Type.getMinValue();
+ Upper = Type.getMaxValue();
+ break;
+ }
+ break;
+ case APSIntType::RTR_Within:
+ switch (UpperTest) {
+ case APSIntType::RTR_Below:
+ // The range wraps around, but all lower values are not possible.
+ Type.apply(Lower);
+ Upper = Type.getMaxValue();
+ break;
+ case APSIntType::RTR_Within:
+ // The range may or may not wrap around, but both limits are valid.
+ Type.apply(Lower);
+ Type.apply(Upper);
+ break;
+ case APSIntType::RTR_Above:
+ // The range starts within what's possible but ends above it. Pin.
+ Type.apply(Lower);
+ Upper = Type.getMaxValue();
+ break;
+ }
+ break;
+ case APSIntType::RTR_Above:
+ switch (UpperTest) {
+ case APSIntType::RTR_Below:
+ // The range wraps but is outside the symbol's set of possible values.
+ return false;
+ case APSIntType::RTR_Within:
+ // The range starts above what's possible but ends within it (wrap).
+ Lower = Type.getMinValue();
+ Type.apply(Upper);
+ break;
+ case APSIntType::RTR_Above:
+ // The entire range is outside the symbol's set of possible values.
+ // If this is a conventionally-ordered range, the state is infeasible.
+ if (Lower < Upper)
+ return false;
+
+ // However, if the range wraps around, it spans all possible values.
+ Lower = Type.getMinValue();
+ Upper = Type.getMaxValue();
+ break;
+ }
+ break;
+ }
+
+ return true;
+ }
+
public:
// Returns a set containing the values in the receiving set, intersected with
// the closed range [Lower, Upper]. Unlike the Range type, this range uses
@@ -152,8 +239,10 @@
// intersection with the two ranges [Min, Upper] and [Lower, Max],
// or, alternatively, /removing/ all integers between Upper and Lower.
RangeSet Intersect(BasicValueFactory &BV, Factory &F,
- const llvm::APSInt &Lower,
- const llvm::APSInt &Upper) const {
+ llvm::APSInt Lower, llvm::APSInt Upper) const {
+ if (!pin(Lower, Upper))
+ return F.getEmptySet();
+
PrimRangeSet newRanges = F.getEmptySet();
PrimRangeSet::iterator i = begin(), e = end();
@@ -166,6 +255,7 @@
IntersectInRange(BV, F, BV.getMinValue(Upper), Upper, newRanges, i, e);
IntersectInRange(BV, F, Lower, BV.getMaxValue(Lower), newRanges, i, e);
}
+
return newRanges;
}
@@ -206,8 +296,8 @@
class RangeConstraintManager : public SimpleConstraintManager{
RangeSet GetRange(ProgramStateRef state, SymbolRef sym);
public:
- RangeConstraintManager(SubEngine &subengine)
- : SimpleConstraintManager(subengine) {}
+ RangeConstraintManager(SubEngine &subengine, BasicValueFactory &BVF)
+ : SimpleConstraintManager(subengine, BVF) {}
ProgramStateRef assumeSymNE(ProgramStateRef state, SymbolRef sym,
const llvm::APSInt& Int,
@@ -252,9 +342,9 @@
} // end anonymous namespace
-ConstraintManager* ento::CreateRangeConstraintManager(ProgramStateManager&,
- SubEngine &subeng) {
- return new RangeConstraintManager(subeng);
+ConstraintManager *
+ento::CreateRangeConstraintManager(ProgramStateManager &StMgr, SubEngine &Eng) {
+ return new RangeConstraintManager(Eng, StMgr.getBasicVals());
}
const llvm::APSInt* RangeConstraintManager::getSymVal(ProgramStateRef St,
@@ -288,8 +378,8 @@
// Lazily generate a new RangeSet representing all possible values for the
// given symbol type.
- QualType T = state->getSymbolManager().getType(sym);
- BasicValueFactory& BV = state->getBasicVals();
+ BasicValueFactory &BV = getBasicVals();
+ QualType T = sym->getType(BV.getContext());
return RangeSet(F, BV.getMinValue(T), BV.getMaxValue(T));
}
@@ -306,117 +396,154 @@
// UINT_MAX, 0, 1, and 2.
ProgramStateRef
-RangeConstraintManager::assumeSymNE(ProgramStateRef state, SymbolRef sym,
- const llvm::APSInt& Int,
- const llvm::APSInt& Adjustment) {
- BasicValueFactory &BV = state->getBasicVals();
+RangeConstraintManager::assumeSymNE(ProgramStateRef St, SymbolRef Sym,
+ const llvm::APSInt &Int,
+ const llvm::APSInt &Adjustment) {
+ // Before we do any real work, see if the value can even show up.
+ APSIntType AdjustmentType(Adjustment);
+ if (AdjustmentType.testInRange(Int) != APSIntType::RTR_Within)
+ return St;
- llvm::APSInt Lower = Int-Adjustment;
+ llvm::APSInt Lower = AdjustmentType.convert(Int) - Adjustment;
llvm::APSInt Upper = Lower;
--Lower;
++Upper;
// [Int-Adjustment+1, Int-Adjustment-1]
// Notice that the lower bound is greater than the upper bound.
- RangeSet New = GetRange(state, sym).Intersect(BV, F, Upper, Lower);
- return New.isEmpty() ? NULL : state->set<ConstraintRange>(sym, New);
+ RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Upper, Lower);
+ return New.isEmpty() ? NULL : St->set<ConstraintRange>(Sym, New);
}
ProgramStateRef
-RangeConstraintManager::assumeSymEQ(ProgramStateRef state, SymbolRef sym,
- const llvm::APSInt& Int,
- const llvm::APSInt& Adjustment) {
+RangeConstraintManager::assumeSymEQ(ProgramStateRef St, SymbolRef Sym,
+ const llvm::APSInt &Int,
+ const llvm::APSInt &Adjustment) {
+ // Before we do any real work, see if the value can even show up.
+ APSIntType AdjustmentType(Adjustment);
+ if (AdjustmentType.testInRange(Int) != APSIntType::RTR_Within)
+ return NULL;
+
// [Int-Adjustment, Int-Adjustment]
- BasicValueFactory &BV = state->getBasicVals();
- llvm::APSInt AdjInt = Int-Adjustment;
- RangeSet New = GetRange(state, sym).Intersect(BV, F, AdjInt, AdjInt);
- return New.isEmpty() ? NULL : state->set<ConstraintRange>(sym, New);
+ llvm::APSInt AdjInt = AdjustmentType.convert(Int) - Adjustment;
+ RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, AdjInt, AdjInt);
+ return New.isEmpty() ? NULL : St->set<ConstraintRange>(Sym, New);
}
ProgramStateRef
-RangeConstraintManager::assumeSymLT(ProgramStateRef state, SymbolRef sym,
- const llvm::APSInt& Int,
- const llvm::APSInt& Adjustment) {
- BasicValueFactory &BV = state->getBasicVals();
-
- QualType T = state->getSymbolManager().getType(sym);
- const llvm::APSInt &Min = BV.getMinValue(T);
+RangeConstraintManager::assumeSymLT(ProgramStateRef St, SymbolRef Sym,
+ const llvm::APSInt &Int,
+ const llvm::APSInt &Adjustment) {
+ // Before we do any real work, see if the value can even show up.
+ APSIntType AdjustmentType(Adjustment);
+ switch (AdjustmentType.testInRange(Int)) {
+ case APSIntType::RTR_Below:
+ return NULL;
+ case APSIntType::RTR_Within:
+ break;
+ case APSIntType::RTR_Above:
+ return St;
+ }
// Special case for Int == Min. This is always false.
- if (Int == Min)
+ llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
+ llvm::APSInt Min = AdjustmentType.getMinValue();
+ if (ComparisonVal == Min)
return NULL;
llvm::APSInt Lower = Min-Adjustment;
- llvm::APSInt Upper = Int-Adjustment;
+ llvm::APSInt Upper = ComparisonVal-Adjustment;
--Upper;
- RangeSet New = GetRange(state, sym).Intersect(BV, F, Lower, Upper);
- return New.isEmpty() ? NULL : state->set<ConstraintRange>(sym, New);
+ RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
+ return New.isEmpty() ? NULL : St->set<ConstraintRange>(Sym, New);
}
ProgramStateRef
-RangeConstraintManager::assumeSymGT(ProgramStateRef state, SymbolRef sym,
- const llvm::APSInt& Int,
- const llvm::APSInt& Adjustment) {
- BasicValueFactory &BV = state->getBasicVals();
-
- QualType T = state->getSymbolManager().getType(sym);
- const llvm::APSInt &Max = BV.getMaxValue(T);
+RangeConstraintManager::assumeSymGT(ProgramStateRef St, SymbolRef Sym,
+ const llvm::APSInt &Int,
+ const llvm::APSInt &Adjustment) {
+ // Before we do any real work, see if the value can even show up.
+ APSIntType AdjustmentType(Adjustment);
+ switch (AdjustmentType.testInRange(Int)) {
+ case APSIntType::RTR_Below:
+ return St;
+ case APSIntType::RTR_Within:
+ break;
+ case APSIntType::RTR_Above:
+ return NULL;
+ }
// Special case for Int == Max. This is always false.
- if (Int == Max)
+ llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
+ llvm::APSInt Max = AdjustmentType.getMaxValue();
+ if (ComparisonVal == Max)
return NULL;
- llvm::APSInt Lower = Int-Adjustment;
+ llvm::APSInt Lower = ComparisonVal-Adjustment;
llvm::APSInt Upper = Max-Adjustment;
++Lower;
- RangeSet New = GetRange(state, sym).Intersect(BV, F, Lower, Upper);
- return New.isEmpty() ? NULL : state->set<ConstraintRange>(sym, New);
+ RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
+ return New.isEmpty() ? NULL : St->set<ConstraintRange>(Sym, New);
}
ProgramStateRef
-RangeConstraintManager::assumeSymGE(ProgramStateRef state, SymbolRef sym,
- const llvm::APSInt& Int,
- const llvm::APSInt& Adjustment) {
- BasicValueFactory &BV = state->getBasicVals();
-
- QualType T = state->getSymbolManager().getType(sym);
- const llvm::APSInt &Min = BV.getMinValue(T);
+RangeConstraintManager::assumeSymGE(ProgramStateRef St, SymbolRef Sym,
+ const llvm::APSInt &Int,
+ const llvm::APSInt &Adjustment) {
+ // Before we do any real work, see if the value can even show up.
+ APSIntType AdjustmentType(Adjustment);
+ switch (AdjustmentType.testInRange(Int)) {
+ case APSIntType::RTR_Below:
+ return St;
+ case APSIntType::RTR_Within:
+ break;
+ case APSIntType::RTR_Above:
+ return NULL;
+ }
// Special case for Int == Min. This is always feasible.
- if (Int == Min)
- return state;
-
- const llvm::APSInt &Max = BV.getMaxValue(T);
+ llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
+ llvm::APSInt Min = AdjustmentType.getMinValue();
+ if (ComparisonVal == Min)
+ return St;
- llvm::APSInt Lower = Int-Adjustment;
+ llvm::APSInt Max = AdjustmentType.getMaxValue();
+ llvm::APSInt Lower = ComparisonVal-Adjustment;
llvm::APSInt Upper = Max-Adjustment;
- RangeSet New = GetRange(state, sym).Intersect(BV, F, Lower, Upper);
- return New.isEmpty() ? NULL : state->set<ConstraintRange>(sym, New);
+ RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
+ return New.isEmpty() ? NULL : St->set<ConstraintRange>(Sym, New);
}
ProgramStateRef
-RangeConstraintManager::assumeSymLE(ProgramStateRef state, SymbolRef sym,
- const llvm::APSInt& Int,
- const llvm::APSInt& Adjustment) {
- BasicValueFactory &BV = state->getBasicVals();
-
- QualType T = state->getSymbolManager().getType(sym);
- const llvm::APSInt &Max = BV.getMaxValue(T);
+RangeConstraintManager::assumeSymLE(ProgramStateRef St, SymbolRef Sym,
+ const llvm::APSInt &Int,
+ const llvm::APSInt &Adjustment) {
+ // Before we do any real work, see if the value can even show up.
+ APSIntType AdjustmentType(Adjustment);
+ switch (AdjustmentType.testInRange(Int)) {
+ case APSIntType::RTR_Below:
+ return NULL;
+ case APSIntType::RTR_Within:
+ break;
+ case APSIntType::RTR_Above:
+ return St;
+ }
// Special case for Int == Max. This is always feasible.
- if (Int == Max)
- return state;
-
- const llvm::APSInt &Min = BV.getMinValue(T);
+ llvm::APSInt ComparisonVal = AdjustmentType.convert(Int);
+ llvm::APSInt Max = AdjustmentType.getMaxValue();
+ if (ComparisonVal == Max)
+ return St;
+ llvm::APSInt Min = AdjustmentType.getMinValue();
llvm::APSInt Lower = Min-Adjustment;
- llvm::APSInt Upper = Int-Adjustment;
+ llvm::APSInt Upper = ComparisonVal-Adjustment;
- RangeSet New = GetRange(state, sym).Intersect(BV, F, Lower, Upper);
- return New.isEmpty() ? NULL : state->set<ConstraintRange>(sym, New);
+ RangeSet New = GetRange(St, Sym).Intersect(getBasicVals(), F, Lower, Upper);
+ return New.isEmpty() ? NULL : St->set<ConstraintRange>(Sym, New);
}
//===------------------------------------------------------------------------===
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/RegionStore.cpp Tue May 8 03:47:31 2012
@@ -681,8 +681,22 @@
BI != BE; ++BI) {
const VarRegion *VR = *BI;
const VarDecl *VD = VR->getDecl();
- if (VD->getAttr<BlocksAttr>() || !VD->hasLocalStorage())
+ if (VD->getAttr<BlocksAttr>() || !VD->hasLocalStorage()) {
AddToWorkList(VR);
+ }
+ else if (Loc::isLocType(VR->getValueType())) {
+ // Map the current bindings to a Store to retrieve the value
+ // of the binding. If that binding itself is a region, we should
+ // invalidate that region. This is because a block may capture
+ // a pointer value, but the thing pointed by that pointer may
+ // get invalidated.
+ Store store = B.getRootWithoutRetain();
+ SVal V = RM.getBinding(store, loc::MemRegionVal(VR));
+ if (const Loc *L = dyn_cast<Loc>(&V)) {
+ if (const MemRegion *LR = L->getAsRegion())
+ AddToWorkList(LR);
+ }
+ }
}
return;
}
@@ -1646,11 +1660,11 @@
break;
// Skip any unnamed bitfields to stay in sync with the initializers.
- if ((*FI)->isUnnamedBitfield())
+ if (FI->isUnnamedBitfield())
continue;
- QualType FTy = (*FI)->getType();
- const FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
+ QualType FTy = FI->getType();
+ const FieldRegion* FR = MRMgr.getFieldRegion(&*FI, R);
if (FTy->isArrayType())
newStore = BindArray(newStore.getStore(), FR, *VI);
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/SValBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/SValBuilder.cpp Tue May 8 03:47:31 2012
@@ -61,7 +61,6 @@
NonLoc SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const SymExpr *rhs, QualType type) {
assert(lhs && rhs);
- assert(haveSameType(lhs->getType(Context), rhs->getType(Context)) == true);
assert(!Loc::isLocType(type));
return nonloc::SymbolVal(SymMgr.getSymSymExpr(lhs, op, rhs, type));
}
@@ -195,29 +194,31 @@
//===----------------------------------------------------------------------===//
-SVal SValBuilder::makeGenericVal(ProgramStateRef State,
- BinaryOperator::Opcode Op,
- NonLoc LHS, NonLoc RHS,
- QualType ResultTy) {
- // If operands are tainted, create a symbol to ensure that we propagate taint.
- if (State->isTainted(RHS) || State->isTainted(LHS)) {
- const SymExpr *symLHS;
- const SymExpr *symRHS;
+SVal SValBuilder::makeSymExprValNN(ProgramStateRef State,
+ BinaryOperator::Opcode Op,
+ NonLoc LHS, NonLoc RHS,
+ QualType ResultTy) {
+ if (!State->isTainted(RHS) && !State->isTainted(LHS))
+ return UnknownVal();
+
+ const SymExpr *symLHS = LHS.getAsSymExpr();
+ const SymExpr *symRHS = RHS.getAsSymExpr();
+ // TODO: When the Max Complexity is reached, we should conjure a symbol
+ // instead of generating an Unknown value and propagate the taint info to it.
+ const unsigned MaxComp = 10000; // 100000 28X
+
+ if (symLHS && symRHS &&
+ (symLHS->computeComplexity() + symRHS->computeComplexity()) < MaxComp)
+ return makeNonLoc(symLHS, Op, symRHS, ResultTy);
- if (const nonloc::ConcreteInt *rInt = dyn_cast<nonloc::ConcreteInt>(&RHS)) {
- symLHS = LHS.getAsSymExpr();
+ if (symLHS && symLHS->computeComplexity() < MaxComp)
+ if (const nonloc::ConcreteInt *rInt = dyn_cast<nonloc::ConcreteInt>(&RHS))
return makeNonLoc(symLHS, Op, rInt->getValue(), ResultTy);
- }
- if (const nonloc::ConcreteInt *lInt = dyn_cast<nonloc::ConcreteInt>(&LHS)) {
- symRHS = RHS.getAsSymExpr();
+ if (symRHS && symRHS->computeComplexity() < MaxComp)
+ if (const nonloc::ConcreteInt *lInt = dyn_cast<nonloc::ConcreteInt>(&LHS))
return makeNonLoc(lInt->getValue(), Op, symRHS, ResultTy);
- }
- symLHS = LHS.getAsSymExpr();
- symRHS = RHS.getAsSymExpr();
- return makeNonLoc(symLHS, Op, symRHS, ResultTy);
- }
return UnknownVal();
}
@@ -340,9 +341,12 @@
// Check for casts from a region to a specific type.
if (const MemRegion *R = val.getAsRegion()) {
+ // Handle other casts of locations to integers.
+ if (castTy->isIntegerType())
+ return evalCastFromLoc(loc::MemRegionVal(R), castTy);
+
// FIXME: We should handle the case where we strip off view layers to get
// to a desugared type.
-
if (!Loc::isLocType(castTy)) {
// FIXME: There can be gross cases where one casts the result of a function
// (that returns a pointer) to some other value that happens to fit
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp Tue May 8 03:47:31 2012
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "SimpleConstraintManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -71,9 +72,6 @@
ProgramStateRef SimpleConstraintManager::assumeAux(ProgramStateRef state,
Loc Cond, bool Assumption) {
-
- BasicValueFactory &BasicVals = state->getBasicVals();
-
switch (Cond.getSubKind()) {
default:
assert (false && "'Assume' not implemented for this Loc.");
@@ -88,7 +86,7 @@
while (SubR) {
// FIXME: now we only find the first symbolic region.
if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(SubR)) {
- const llvm::APSInt &zero = BasicVals.getZeroWithPtrWidth();
+ const llvm::APSInt &zero = getBasicVals().getZeroWithPtrWidth();
if (Assumption)
return assumeSymNE(state, SymR->getSymbol(), zero, zero);
else
@@ -134,12 +132,12 @@
}
-ProgramStateRef SimpleConstraintManager::assumeAuxForSymbol(
- ProgramStateRef State,
- SymbolRef Sym,
- bool Assumption) {
- QualType T = State->getSymbolManager().getType(Sym);
- const llvm::APSInt &zero = State->getBasicVals().getValue(0, T);
+ProgramStateRef
+SimpleConstraintManager::assumeAuxForSymbol(ProgramStateRef State,
+ SymbolRef Sym, bool Assumption) {
+ BasicValueFactory &BVF = getBasicVals();
+ QualType T = Sym->getType(BVF.getContext());
+ const llvm::APSInt &zero = BVF.getValue(0, T);
if (Assumption)
return assumeSymNE(State, Sym, zero, zero);
else
@@ -158,8 +156,7 @@
return assumeAuxForSymbol(state, sym, Assumption);
}
- BasicValueFactory &BasicVals = state->getBasicVals();
- SymbolManager &SymMgr = state->getSymbolManager();
+ BasicValueFactory &BasicVals = getBasicVals();
switch (Cond.getSubKind()) {
default:
@@ -184,7 +181,7 @@
BinaryOperator::Opcode op = SE->getOpcode();
// Implicitly compare non-comparison expressions to 0.
if (!BinaryOperator::isComparisonOp(op)) {
- QualType T = SymMgr.getType(SE);
+ QualType T = SE->getType(BasicVals.getContext());
const llvm::APSInt &zero = BasicVals.getValue(0, T);
op = (Assumption ? BO_NE : BO_EQ);
return assumeSymRel(state, SE, op, zero);
@@ -209,33 +206,20 @@
} // end switch
}
-static llvm::APSInt computeAdjustment(const SymExpr *LHS,
- SymbolRef &Sym) {
- llvm::APSInt DefaultAdjustment;
- DefaultAdjustment = 0;
-
- // First check if the LHS is a simple symbol reference.
- if (isa<SymbolData>(LHS))
- return DefaultAdjustment;
-
- // Next, see if it's a "($sym+constant1)" expression.
- const SymIntExpr *SE = dyn_cast<SymIntExpr>(LHS);
-
- // We cannot simplify "($sym1+$sym2)".
- if (!SE)
- return DefaultAdjustment;
-
- // Get the constant out of the expression "($sym+constant1)" or
- // "<expr>+constant1".
- Sym = SE->getLHS();
- switch (SE->getOpcode()) {
- case BO_Add:
- return SE->getRHS();
- case BO_Sub:
- return -SE->getRHS();
- default:
- // We cannot simplify non-additive operators.
- return DefaultAdjustment;
+static void computeAdjustment(SymbolRef &Sym, llvm::APSInt &Adjustment) {
+ // Is it a "($sym+constant1)" expression?
+ if (const SymIntExpr *SE = dyn_cast<SymIntExpr>(Sym)) {
+ BinaryOperator::Opcode Op = SE->getOpcode();
+ if (Op == BO_Add || Op == BO_Sub) {
+ Sym = SE->getLHS();
+ Adjustment = APSIntType(Adjustment).convert(SE->getRHS());
+
+ // Don't forget to negate the adjustment if it's being subtracted.
+ // This should happen /after/ promotion, in case the value being
+ // subtracted is, say, CHAR_MIN, and the promoted type is 'int'.
+ if (Op == BO_Sub)
+ Adjustment = -Adjustment;
+ }
}
}
@@ -246,6 +230,12 @@
assert(BinaryOperator::isComparisonOp(op) &&
"Non-comparison ops should be rewritten as comparisons to zero.");
+ BasicValueFactory &BVF = getBasicVals();
+ ASTContext &Ctx = BVF.getContext();
+
+ // Get the type used for calculating wraparound.
+ APSIntType WraparoundType = BVF.getAPSIntType(LHS->getType(Ctx));
+
// We only handle simple comparisons of the form "$sym == constant"
// or "($sym+constant1) == constant2".
// The adjustment is "constant1" in the above expression. It's used to
@@ -254,28 +244,12 @@
// in modular arithmetic is [0, 1] U [UINT_MAX-1, UINT_MAX]. It's up to
// the subclasses of SimpleConstraintManager to handle the adjustment.
SymbolRef Sym = LHS;
- llvm::APSInt Adjustment = computeAdjustment(LHS, Sym);
+ llvm::APSInt Adjustment = WraparoundType.getZeroValue();
+ computeAdjustment(Sym, Adjustment);
- // FIXME: This next section is a hack. It silently converts the integers to
- // be of the same type as the symbol, which is not always correct. Really the
- // comparisons should be performed using the Int's type, then mapped back to
- // the symbol's range of values.
- ProgramStateManager &StateMgr = state->getStateManager();
- ASTContext &Ctx = StateMgr.getContext();
-
- QualType T = Sym->getType(Ctx);
- assert(T->isIntegerType() || Loc::isLocType(T));
- unsigned bitwidth = Ctx.getTypeSize(T);
- bool isSymUnsigned
- = T->isUnsignedIntegerOrEnumerationType() || Loc::isLocType(T);
-
- // Convert the adjustment.
- Adjustment.setIsUnsigned(isSymUnsigned);
- Adjustment = Adjustment.extOrTrunc(bitwidth);
-
- // Convert the right-hand side integer.
- llvm::APSInt ConvertedInt(Int, isSymUnsigned);
- ConvertedInt = ConvertedInt.extOrTrunc(bitwidth);
+ // Convert the right-hand side integer as necessary.
+ APSIntType ComparisonType = std::max(WraparoundType, APSIntType(Int));
+ llvm::APSInt ConvertedInt = ComparisonType.convert(Int);
switch (op) {
default:
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.h?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.h (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleConstraintManager.h Tue May 8 03:47:31 2012
@@ -23,8 +23,10 @@
class SimpleConstraintManager : public ConstraintManager {
SubEngine &SU;
+ BasicValueFactory &BVF;
public:
- SimpleConstraintManager(SubEngine &subengine) : SU(subengine) {}
+ SimpleConstraintManager(SubEngine &subengine, BasicValueFactory &BV)
+ : SU(subengine), BVF(BV) {}
virtual ~SimpleConstraintManager();
//===------------------------------------------------------------------===//
@@ -79,6 +81,8 @@
// Internal implementation.
//===------------------------------------------------------------------===//
+ BasicValueFactory &getBasicVals() const { return BVF; }
+
bool canReasonAbout(SVal X) const;
ProgramStateRef assumeAux(ProgramStateRef state,
Modified: cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp?rev=156378&r1=156377&r2=156378&view=diff
==============================================================================
--- cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original)
+++ cfe/branches/tooling/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Tue May 8 03:47:31 2012
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -106,9 +107,7 @@
return UnknownVal();
llvm::APSInt i = cast<nonloc::ConcreteInt>(val).getValue();
- i.setIsUnsigned(castTy->isUnsignedIntegerOrEnumerationType() ||
- Loc::isLocType(castTy));
- i = i.extOrTrunc(Context.getTypeSize(castTy));
+ BasicVals.getAPSIntType(castTy).apply(i);
if (isLocType)
return makeIntLocVal(i);
@@ -139,9 +138,7 @@
return makeLocAsInteger(val, BitWidth);
llvm::APSInt i = cast<loc::ConcreteInt>(val).getValue();
- i.setIsUnsigned(castTy->isUnsignedIntegerOrEnumerationType() ||
- Loc::isLocType(castTy));
- i = i.extOrTrunc(BitWidth);
+ BasicVals.getAPSIntType(castTy).apply(i);
return makeIntVal(i);
}
@@ -272,14 +269,40 @@
return evalCastFromNonLoc(nonloc::SymbolVal(LHS), resultTy);
// If we reach this point, the expression cannot be simplified.
- // Make a SymbolVal for the entire expression.
- return makeNonLoc(LHS, op, RHS, resultTy);
+ // Make a SymbolVal for the entire expression, after converting the RHS.
+ const llvm::APSInt *ConvertedRHS = &RHS;
+ if (BinaryOperator::isComparisonOp(op)) {
+ // We're looking for a type big enough to compare the symbolic value
+ // with the given constant.
+ // FIXME: This is an approximation of Sema::UsualArithmeticConversions.
+ ASTContext &Ctx = getContext();
+ QualType SymbolType = LHS->getType(Ctx);
+ uint64_t ValWidth = RHS.getBitWidth();
+ uint64_t TypeWidth = Ctx.getTypeSize(SymbolType);
+
+ if (ValWidth < TypeWidth) {
+ // If the value is too small, extend it.
+ ConvertedRHS = &BasicVals.Convert(SymbolType, RHS);
+ } else if (ValWidth == TypeWidth) {
+ // If the value is signed but the symbol is unsigned, do the comparison
+ // in unsigned space. [C99 6.3.1.8]
+ // (For the opposite case, the value is already unsigned.)
+ if (RHS.isSigned() && !SymbolType->isSignedIntegerOrEnumerationType())
+ ConvertedRHS = &BasicVals.Convert(SymbolType, RHS);
+ }
+ } else
+ ConvertedRHS = &BasicVals.Convert(resultTy, RHS);
+
+ return makeNonLoc(LHS, op, *ConvertedRHS, resultTy);
}
SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
BinaryOperator::Opcode op,
NonLoc lhs, NonLoc rhs,
QualType resultTy) {
+ NonLoc InputLHS = lhs;
+ NonLoc InputRHS = rhs;
+
// Handle trivial case where left-side and right-side are the same.
if (lhs == rhs)
switch (op) {
@@ -304,7 +327,7 @@
while (1) {
switch (lhs.getSubKind()) {
default:
- return makeGenericVal(state, op, lhs, rhs, resultTy);
+ return makeSymExprValNN(state, op, lhs, rhs, resultTy);
case nonloc::LocAsIntegerKind: {
Loc lhsL = cast<nonloc::LocAsInteger>(lhs).getLoc();
switch (rhs.getSubKind()) {
@@ -315,8 +338,7 @@
case nonloc::ConcreteIntKind: {
// Transform the integer into a location and compare.
llvm::APSInt i = cast<nonloc::ConcreteInt>(rhs).getValue();
- i.setIsUnsigned(true);
- i = i.extOrTrunc(Context.getTypeSize(Context.VoidPtrTy));
+ BasicVals.getAPSIntType(Context.VoidPtrTy).apply(i);
return evalBinOpLL(state, op, lhsL, makeLoc(i), resultTy);
}
default:
@@ -327,86 +349,78 @@
return makeTruthVal(true, resultTy);
default:
// This case also handles pointer arithmetic.
- return makeGenericVal(state, op, lhs, rhs, resultTy);
+ return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
}
}
}
case nonloc::ConcreteIntKind: {
- const nonloc::ConcreteInt& lhsInt = cast<nonloc::ConcreteInt>(lhs);
-
- // Is the RHS a symbol we can simplify?
- // FIXME: This was mostly copy/pasted from the LHS-is-a-symbol case.
- if (const nonloc::SymbolVal *srhs = dyn_cast<nonloc::SymbolVal>(&rhs)) {
- SymbolRef RSym = srhs->getSymbol();
- if (RSym->getType(Context)->isIntegerType()) {
- if (const llvm::APSInt *Constant = state->getSymVal(RSym)) {
- // The symbol evaluates to a constant.
- const llvm::APSInt *rhs_I;
- if (BinaryOperator::isRelationalOp(op))
- rhs_I = &BasicVals.Convert(lhsInt.getValue(), *Constant);
- else
- rhs_I = &BasicVals.Convert(resultTy, *Constant);
+ llvm::APSInt LHSValue = cast<nonloc::ConcreteInt>(lhs).getValue();
- rhs = nonloc::ConcreteInt(*rhs_I);
- }
+ // If we're dealing with two known constants, just perform the operation.
+ if (const llvm::APSInt *KnownRHSValue = getKnownValue(state, rhs)) {
+ llvm::APSInt RHSValue = *KnownRHSValue;
+ if (BinaryOperator::isComparisonOp(op)) {
+ // We're looking for a type big enough to compare the two values.
+ // FIXME: This is not correct. char + short will result in a promotion
+ // to int. Unfortunately we have lost types by this point.
+ APSIntType CompareType = std::max(APSIntType(LHSValue),
+ APSIntType(RHSValue));
+ CompareType.apply(LHSValue);
+ CompareType.apply(RHSValue);
+ } else if (!BinaryOperator::isShiftOp(op)) {
+ APSIntType IntType = BasicVals.getAPSIntType(resultTy);
+ IntType.apply(LHSValue);
+ IntType.apply(RHSValue);
}
- }
- if (isa<nonloc::ConcreteInt>(rhs)) {
- return lhsInt.evalBinOp(*this, op, cast<nonloc::ConcreteInt>(rhs));
- } else {
- const llvm::APSInt& lhsValue = lhsInt.getValue();
-
- // Swap the left and right sides and flip the operator if doing so
- // allows us to better reason about the expression (this is a form
- // of expression canonicalization).
- // While we're at it, catch some special cases for non-commutative ops.
- NonLoc tmp = rhs;
- rhs = lhs;
- lhs = tmp;
+ const llvm::APSInt *Result =
+ BasicVals.evalAPSInt(op, LHSValue, RHSValue);
+ if (!Result)
+ return UndefinedVal();
+
+ return nonloc::ConcreteInt(*Result);
+ }
- switch (op) {
- case BO_LT:
- case BO_GT:
- case BO_LE:
- case BO_GE:
- op = ReverseComparison(op);
- continue;
- case BO_EQ:
- case BO_NE:
- case BO_Add:
- case BO_Mul:
- case BO_And:
- case BO_Xor:
- case BO_Or:
- continue;
- case BO_Shr:
- if (lhsValue.isAllOnesValue() && lhsValue.isSigned())
- // At this point lhs and rhs have been swapped.
- return rhs;
- // FALL-THROUGH
- case BO_Shl:
- if (lhsValue == 0)
- // At this point lhs and rhs have been swapped.
- return rhs;
- return makeGenericVal(state, op, rhs, lhs, resultTy);
- default:
- return makeGenericVal(state, op, rhs, lhs, resultTy);
- }
+ // Swap the left and right sides and flip the operator if doing so
+ // allows us to better reason about the expression (this is a form
+ // of expression canonicalization).
+ // While we're at it, catch some special cases for non-commutative ops.
+ switch (op) {
+ case BO_LT:
+ case BO_GT:
+ case BO_LE:
+ case BO_GE:
+ op = ReverseComparison(op);
+ // FALL-THROUGH
+ case BO_EQ:
+ case BO_NE:
+ case BO_Add:
+ case BO_Mul:
+ case BO_And:
+ case BO_Xor:
+ case BO_Or:
+ std::swap(lhs, rhs);
+ continue;
+ case BO_Shr:
+ // (~0)>>a
+ if (LHSValue.isAllOnesValue() && LHSValue.isSigned())
+ return evalCastFromNonLoc(lhs, resultTy);
+ // FALL-THROUGH
+ case BO_Shl:
+ // 0<<a and 0>>a
+ if (LHSValue == 0)
+ return evalCastFromNonLoc(lhs, resultTy);
+ return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
+ default:
+ return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
}
}
case nonloc::SymbolValKind: {
- nonloc::SymbolVal *selhs = cast<nonloc::SymbolVal>(&lhs);
+ // We only handle LHS as simple symbols or SymIntExprs.
+ SymbolRef Sym = cast<nonloc::SymbolVal>(lhs).getSymbol();
// LHS is a symbolic expression.
- if (selhs->isExpression()) {
-
- // Only handle LHS of the form "$sym op constant", at least for now.
- const SymIntExpr *symIntExpr =
- dyn_cast<SymIntExpr>(selhs->getSymbol());
-
- if (!symIntExpr)
- return makeGenericVal(state, op, lhs, rhs, resultTy);
+ if (const SymIntExpr *symIntExpr = dyn_cast<SymIntExpr>(Sym)) {
// Is this a logical not? (!x is represented as x == 0.)
if (op == BO_EQ && rhs.isZeroConstant()) {
@@ -452,95 +466,57 @@
}
// For now, only handle expressions whose RHS is a constant.
- const nonloc::ConcreteInt *rhsInt = dyn_cast<nonloc::ConcreteInt>(&rhs);
- if (!rhsInt)
- return makeGenericVal(state, op, lhs, rhs, resultTy);
-
- // If both the LHS and the current expression are additive,
- // fold their constants.
- if (BinaryOperator::isAdditiveOp(op)) {
- BinaryOperator::Opcode lop = symIntExpr->getOpcode();
- if (BinaryOperator::isAdditiveOp(lop)) {
- // resultTy may not be the best type to convert to, but it's
- // probably the best choice in expressions with mixed type
- // (such as x+1U+2LL). The rules for implicit conversions should
- // choose a reasonable type to preserve the expression, and will
- // at least match how the value is going to be used.
- const llvm::APSInt &first =
- BasicVals.Convert(resultTy, symIntExpr->getRHS());
- const llvm::APSInt &second =
- BasicVals.Convert(resultTy, rhsInt->getValue());
- const llvm::APSInt *newRHS;
- if (lop == op)
- newRHS = BasicVals.evalAPSInt(BO_Add, first, second);
- else
- newRHS = BasicVals.evalAPSInt(BO_Sub, first, second);
- return MakeSymIntVal(symIntExpr->getLHS(), lop, *newRHS, resultTy);
- }
- }
-
- // Otherwise, make a SymbolVal out of the expression.
- return MakeSymIntVal(symIntExpr, op, rhsInt->getValue(), resultTy);
-
- // LHS is a simple symbol (not a symbolic expression).
- } else {
- nonloc::SymbolVal *slhs = cast<nonloc::SymbolVal>(&lhs);
- SymbolRef Sym = slhs->getSymbol();
- QualType lhsType = Sym->getType(Context);
-
- // The conversion type is usually the result type, but not in the case
- // of relational expressions.
- QualType conversionType = resultTy;
- if (BinaryOperator::isRelationalOp(op))
- conversionType = lhsType;
-
- // Does the symbol simplify to a constant? If so, "fold" the constant
- // by setting 'lhs' to a ConcreteInt and try again.
- if (lhsType->isIntegerType())
- if (const llvm::APSInt *Constant = state->getSymVal(Sym)) {
- // The symbol evaluates to a constant. If necessary, promote the
- // folded constant (LHS) to the result type.
- const llvm::APSInt &lhs_I = BasicVals.Convert(conversionType,
- *Constant);
- lhs = nonloc::ConcreteInt(lhs_I);
-
- // Also promote the RHS (if necessary).
-
- // For shifts, it is not necessary to promote the RHS.
- if (BinaryOperator::isShiftOp(op))
+ if (const llvm::APSInt *RHSValue = getKnownValue(state, rhs)) {
+ // If both the LHS and the current expression are additive,
+ // fold their constants and try again.
+ if (BinaryOperator::isAdditiveOp(op)) {
+ BinaryOperator::Opcode lop = symIntExpr->getOpcode();
+ if (BinaryOperator::isAdditiveOp(lop)) {
+ // Convert the two constants to a common type, then combine them.
+
+ // resultTy may not be the best type to convert to, but it's
+ // probably the best choice in expressions with mixed type
+ // (such as x+1U+2LL). The rules for implicit conversions should
+ // choose a reasonable type to preserve the expression, and will
+ // at least match how the value is going to be used.
+ APSIntType IntType = BasicVals.getAPSIntType(resultTy);
+ const llvm::APSInt &first = IntType.convert(symIntExpr->getRHS());
+ const llvm::APSInt &second = IntType.convert(*RHSValue);
+
+ const llvm::APSInt *newRHS;
+ if (lop == op)
+ newRHS = BasicVals.evalAPSInt(BO_Add, first, second);
+ else
+ newRHS = BasicVals.evalAPSInt(BO_Sub, first, second);
+
+ assert(newRHS && "Invalid operation despite common type!");
+ rhs = nonloc::ConcreteInt(*newRHS);
+ lhs = nonloc::SymbolVal(symIntExpr->getLHS());
+ op = lop;
continue;
-
- // Other operators: do an implicit conversion. This shouldn't be
- // necessary once we support truncation/extension of symbolic values.
- if (nonloc::ConcreteInt *rhs_I = dyn_cast<nonloc::ConcreteInt>(&rhs)){
- rhs = nonloc::ConcreteInt(BasicVals.Convert(conversionType,
- rhs_I->getValue()));
}
-
- continue;
}
- // Is the RHS a symbol we can simplify?
- if (const nonloc::SymbolVal *srhs = dyn_cast<nonloc::SymbolVal>(&rhs)) {
- SymbolRef RSym = srhs->getSymbol();
- if (RSym->getType(Context)->isIntegerType()) {
- if (const llvm::APSInt *Constant = state->getSymVal(RSym)) {
- // The symbol evaluates to a constant.
- const llvm::APSInt &rhs_I = BasicVals.Convert(conversionType,
- *Constant);
- rhs = nonloc::ConcreteInt(rhs_I);
- }
- }
+ // Otherwise, make a SymIntExpr out of the expression.
+ return MakeSymIntVal(symIntExpr, op, *RHSValue, resultTy);
}
- if (isa<nonloc::ConcreteInt>(rhs)) {
- return MakeSymIntVal(slhs->getSymbol(), op,
- cast<nonloc::ConcreteInt>(rhs).getValue(),
- resultTy);
+
+ } else if (isa<SymbolData>(Sym)) {
+ // Does the symbol simplify to a constant? If so, "fold" the constant
+ // by setting 'lhs' to a ConcreteInt and try again.
+ if (const llvm::APSInt *Constant = state->getSymVal(Sym)) {
+ lhs = nonloc::ConcreteInt(*Constant);
+ continue;
}
- return makeGenericVal(state, op, lhs, rhs, resultTy);
+ // Is the RHS a constant?
+ if (const llvm::APSInt *RHSValue = getKnownValue(state, rhs))
+ return MakeSymIntVal(Sym, op, *RHSValue, resultTy);
}
+
+ // Give up -- this is not a symbolic expression we can handle.
+ return makeSymExprValNN(state, op, InputLHS, InputRHS, resultTy);
}
}
}
@@ -845,9 +821,9 @@
bool leftFirst = (op == BO_LT || op == BO_LE);
for (RecordDecl::field_iterator I = RD->field_begin(),
E = RD->field_end(); I!=E; ++I) {
- if (*I == LeftFD)
+ if (&*I == LeftFD)
return makeTruthVal(leftFirst, resultTy);
- if (*I == RightFD)
+ if (&*I == RightFD)
return makeTruthVal(!leftFirst, resultTy);
}
@@ -885,6 +861,7 @@
return evalBinOpLL(state, op, lhs, loc::ConcreteInt(*x), resultTy);
}
}
+ return UnknownVal();
}
// We are dealing with pointer arithmetic.
More information about the llvm-branch-commits
mailing list