[clang] 5e3ac79 - Loop names used in reporting can grow very large
Author: Jamie Schmeiser Date: 2022-09-09T13:45:14-04:00 New Revision: 5e3ac7969039678fc017a5599b051ea2b78075a4 URL: https://github.com/llvm/llvm-project/commit/5e3ac7969039678fc017a5599b051ea2b78075a4 DIFF: https://github.com/llvm/llvm-project/commit/5e3ac7969039678fc017a5599b051ea2b78075a4.diff LOG: Loop names used in reporting can grow very large Summary: The code for generating a name for loops for various reporting scenarios created a name by serializing the loop into a string. This may result in a very large name for a loop containing many blocks. Use the getName() function on the loop instead. Author: Jamie Schmeiser Reviewed By: Whitney (Whitney Tsang), aeubanks (Arthur Eubanks) Differential Revision: https://reviews.llvm.org/D133587 Added: Modified: clang/test/CodeGen/thinlto-distributed-newpm.ll llvm/lib/Passes/StandardInstrumentations.cpp llvm/test/Other/loop-pass-ordering.ll llvm/test/Other/loop-pass-printer.ll llvm/test/Other/loopnest-pass-ordering.ll llvm/test/Other/new-pm-lto-defaults.ll llvm/test/Other/new-pm-thinlto-defaults.ll llvm/test/Other/pass-pipeline-parsing.ll llvm/test/Other/print-before-after.ll llvm/test/Transforms/LoopPredication/invalidate-analyses.ll llvm/test/Transforms/LoopPredication/preserve-bpi.ll llvm/test/Transforms/LoopRotate/pr35210.ll llvm/test/Transforms/LoopUnroll/revisit.ll llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll Removed: diff --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll b/clang/test/CodeGen/thinlto-distributed-newpm.ll index 463fc522c6a28..3dbc55e23e28d 100644 --- a/clang/test/CodeGen/thinlto-distributed-newpm.ll +++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll @@ -83,7 +83,7 @@ ; CHECK-O: Running pass: LowerConstantIntrinsicsPass on main ; CHECK-O: Running pass: LoopSimplifyPass on main ; CHECK-O: Running pass: LCSSAPass on main -; CHECK-O: Running pass: LoopRotatePass on Loop at depth 1 containing: %b +; CHECK-O: Running pass: LoopRotatePass on b ; CHECK-O: Running pass: LoopDistributePass on main ; CHECK-O: Running pass: InjectTLIMappings on main ; CHECK-O: Running pass: LoopVectorizePass on main @@ -99,7 +99,7 @@ ; CHECK-O: Running pass: RequireAnalysisPass<{{.*}}OptimizationRemarkEmitterAnalysis ; CHECK-O: Running pass: LoopSimplifyPass on main ; CHECK-O: Running pass: LCSSAPass on main -; CHECK-O: Running pass: LICMPass on Loop at depth 1 containing: %b +; CHECK-O: Running pass: LICMPass on b ; CHECK-O: Running pass: AlignmentFromAssumptionsPass on main ; CHECK-O: Running pass: LoopSinkPass on main ; CHECK-O: Running pass: InstSimplifyPass on main diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp index 861e76b38f66b..1ac557d975cec 100644 --- a/llvm/lib/Passes/StandardInstrumentations.cpp +++ b/llvm/lib/Passes/StandardInstrumentations.cpp @@ -188,10 +188,7 @@ std::string getIRName(Any IR) { if (any_isa(IR)) { const Loop *L = any_cast(IR); -std::string S; -raw_string_ostream OS(S); -L->print(OS, /*Verbose*/ false, /*PrintNested*/ false); -return OS.str(); +return L->getName().str(); } llvm_unreachable("Unknown wrapped IR type"); diff --git a/llvm/test/Other/loop-pass-ordering.ll b/llvm/test/Other/loop-pass-ordering.ll index ab3839f5cc997..fde49a7b73a5f 100644 --- a/llvm/test/Other/loop-pass-ordering.ll +++ b/llvm/test/Other/loop-pass-ordering.ll @@ -8,11 +8,11 @@ ; / \\ ; loop.0.0 loop.0.1 loop.1.0 ; -; CHECK: Running pass: NoOpLoopPass on Loop at depth 2 containing: %loop.0.0 -; CHECK: Running pass: NoOpLoopPass on Loop at depth 2 containing: %loop.0.1 -; CHECK: Running pass: NoOpLoopPass on Loop at depth 1 containing: %loop.0 -; CHECK: Running pass: NoOpLoopPass on Loop at depth 2 containing: %loop.1.0 -; CHECK: Running pass: NoOpLoopPass on Loop at depth 1 containing: %loop.1 +; CHECK: Running pass: NoOpLoopPass on loop.0.0 +; CHECK: Running pass: NoOpLoopPass on loop.0.1 +; CHECK: Running pass: NoOpLoopPass on loop.0 +; CHECK: Running pass: NoOpLoopPass on loop.1.0 +; CHECK: Running pass: NoOpLoopPass on loop.1 define void @f() { entry: diff --git a/llvm/test/Other/loop-pass-printer.ll b/llvm/test/Other/loop-pass-printer.ll index 98ad72b142bca..60bfdbbaea9ef 100644 --- a/llvm/test/Other/loop-pass-printer.ll +++ b/llvm/test/Other/loop-pass-printer.ll @@ -35,7 +35,7 @@ ; BAR: ; Exit blocks ; BAR: end: -; FOO-MODULE: IR Dump After {{Unroll|LoopFullUnrollPass}} {{.*}}%loop +; FOO-MODULE: IR Dump After {{Unroll|LoopFullUnrollPass}} {{.*}}loop ; FOO-MODULE-NEXT: ModuleID = ; FOO-MODULE: define void @foo ; FOO-MODULE: define void @bar diff --git a/llvm/test/Other/loopnest-pass-ordering.ll b/llvm/test/Other/loopnest-pass-
[clang] 73840f9 - thread_local support for AIX
Author: Jamie Schmeiser Date: 2021-07-19T10:03:22-04:00 New Revision: 73840f9f81413f21d3c8fab0ed85917aca2b5d34 URL: https://github.com/llvm/llvm-project/commit/73840f9f81413f21d3c8fab0ed85917aca2b5d34 DIFF: https://github.com/llvm/llvm-project/commit/73840f9f81413f21d3c8fab0ed85917aca2b5d34.diff LOG: thread_local support for AIX Summary: The AIX linker will produce errors on unresolved weak symbols. Change the generated code to not check for the initialization function but just call it and ensure that it always exists. Also, the AIX atexit routine has a different name (and signature) so call it correctly. Update the lit tests to test on AIX appropriately. Author: Jamie Schmeiser Reviewed By: hubert.reinterpretcast (Hubert Tong) Differential Revision: https://reviews.llvm.org/D104420 Added: Modified: clang/lib/CodeGen/CGDeclCXX.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp clang/test/CodeGenCXX/cxx11-thread-local-visibility.cpp clang/test/CodeGenCXX/cxx11-thread-local.cpp Removed: diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp index 27a93c243eca0..d43fb99550a85 100644 --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -262,6 +262,58 @@ llvm::Function *CodeGenFunction::createAtExitStub(const VarDecl &VD, return fn; } +/// Create a stub function, suitable for being passed to __pt_atexit_np, +/// which passes the given address to the given destructor function. +llvm::Function *CodeGenFunction::createTLSAtExitStub( +const VarDecl &D, llvm::FunctionCallee Dtor, llvm::Constant *Addr, +llvm::FunctionCallee &AtExit) { + SmallString<256> FnName; + { +llvm::raw_svector_ostream Out(FnName); +CGM.getCXXABI().getMangleContext().mangleDynamicAtExitDestructor(&D, Out); + } + + const CGFunctionInfo &FI = CGM.getTypes().arrangeLLVMFunctionInfo( + getContext().IntTy, /*instanceMethod=*/false, /*chainCall=*/false, + {getContext().IntTy}, FunctionType::ExtInfo(), {}, RequiredArgs::All); + + // Get the stub function type, int(*)(int,...). + llvm::FunctionType *StubTy = + llvm::FunctionType::get(CGM.IntTy, {CGM.IntTy}, true); + + llvm::Function *DtorStub = CGM.CreateGlobalInitOrCleanUpFunction( + StubTy, FnName.str(), FI, D.getLocation()); + + CodeGenFunction CGF(CGM); + + FunctionArgList Args; + ImplicitParamDecl IPD(CGM.getContext(), CGM.getContext().IntTy, +ImplicitParamDecl::Other); + Args.push_back(&IPD); + QualType ResTy = CGM.getContext().IntTy; + + CGF.StartFunction(GlobalDecl(&D, DynamicInitKind::AtExit), ResTy, DtorStub, +FI, Args, D.getLocation(), D.getInit()->getExprLoc()); + + // Emit an artificial location for this function. + auto AL = ApplyDebugLocation::CreateArtificial(CGF); + + llvm::CallInst *call = CGF.Builder.CreateCall(Dtor, Addr); + + // Make sure the call and the callee agree on calling convention. + if (auto *DtorFn = dyn_cast( + Dtor.getCallee()->stripPointerCastsAndAliases())) +call->setCallingConv(DtorFn->getCallingConv()); + + // Return 0 from function + CGF.Builder.CreateStore(llvm::Constant::getNullValue(CGM.IntTy), + CGF.ReturnValue); + + CGF.FinishFunction(); + + return DtorStub; +} + /// Register a global destructor using the C atexit runtime function. void CodeGenFunction::registerGlobalDtorWithAtExit(const VarDecl &VD, llvm::FunctionCallee dtor, diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 75b6bf197c553..e026937f91fe1 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -4369,6 +4369,11 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Function *createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr); + llvm::Function *createTLSAtExitStub(const VarDecl &VD, + llvm::FunctionCallee Dtor, + llvm::Constant *Addr, + llvm::FunctionCallee &AtExit); + /// Call atexit() with a function that passes the given argument to /// the given function. void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn, diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 148986c585c2c..d3dc0e6212b8c 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -337,14 +337,20 @@ class ItaniumCXXABI : public CodeGen::CGCXXABI { /// Determine whether we will definitely emit this variable with a constant /// initializer, either because the language semantics demand i
[clang] 9cb00b9 - Reland Produce warning for performing pointer arithmetic on a null pointer.
Author: Jamie Schmeiser Date: 2021-07-20T10:12:20-04:00 New Revision: 9cb00b9ecbe74d19389a5818d61ddee328afe031 URL: https://github.com/llvm/llvm-project/commit/9cb00b9ecbe74d19389a5818d61ddee328afe031 DIFF: https://github.com/llvm/llvm-project/commit/9cb00b9ecbe74d19389a5818d61ddee328afe031.diff LOG: Reland Produce warning for performing pointer arithmetic on a null pointer. Summary: Test and produce warning for subtracting a pointer from null or subtracting null from a pointer. This reland adds the functionality that the warning is no longer reusing an existing warning, it has different wording for C vs C++ to refect the fact that nullptr-nullptr has defined behaviour in C++, it is suppressed when the warning is triggered by a system header and adds -Wnull-pointer-subtraction to allow the warning to be controlled. -Wextra implies -Wnull-pointer-subtraction. Author: Jamie Schmeiser Reviewed By: efriedma (Eli Friedman), nickdesaulniers (Nick Desaulniers) Differential Revision: https://reviews.llvm.org/D98798 Added: clang/test/Sema/Inputs/pointer-subtraction.h clang/test/Sema/pointer-subtraction.c clang/test/Sema/pointer-subtraction.cpp Modified: clang/docs/ReleaseNotes.rst clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaExpr.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f26c484c5bace..a6f43bcaa4bb3 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -76,6 +76,9 @@ New Compiler Flags file contains frame size information for each function defined in the source file. +- ``-Wnull-pointer-subtraction`` emits warning when user code may have + undefined behaviour due to subtraction involving a null pointer. + Deprecated Compiler Flags - @@ -92,6 +95,7 @@ Modified Compiler Flags instead. ``-B``'s other GCC-compatible semantics are preserved: ``$prefix/$triple-$file`` and ``$prefix$file`` are searched for executables, libraries, includes, and data files used by the compiler. +- ``-Wextra`` now also implies ``-Wnull-pointer-subtraction.`` Removed Compiler Flags - diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index eb1b5641bfdf5..4b4928a7a00e6 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -487,6 +487,7 @@ def ClassVarargs : DiagGroup<"class-varargs", [NonPODVarargs]>; def : DiagGroup<"nonportable-cfstrings">; def NonVirtualDtor : DiagGroup<"non-virtual-dtor">; def NullPointerArithmetic : DiagGroup<"null-pointer-arithmetic">; +def NullPointerSubtraction : DiagGroup<"null-pointer-subtraction">; def : DiagGroup<"effc++", [NonVirtualDtor]>; def OveralignedType : DiagGroup<"over-aligned">; def OldStyleCast : DiagGroup<"old-style-cast">; @@ -932,6 +933,7 @@ def Extra : DiagGroup<"extra", [ UnusedParameter, UnusedButSetParameter, NullPointerArithmetic, +NullPointerSubtraction, EmptyInitStatement, StringConcatation, FUseLdPath, diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 823a36a597c58..792313fed2a9f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6390,6 +6390,9 @@ def warn_pointer_arith_null_ptr : Warning< def warn_gnu_null_ptr_arith : Warning< "arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension">, InGroup, DefaultIgnore; +def warn_pointer_sub_null_ptr : Warning< + "performing pointer subtraction with a null pointer %select{has|may have}0 undefined behavior">, + InGroup, DefaultIgnore; def err_kernel_invalidates_sycl_unique_stable_name : Error<"kernel instantiation changes the result of an evaluated " "'__builtin_sycl_unique_stable_name'">; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index f1c49eb082c20..dcb162952d137 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10432,6 +10432,22 @@ static void diagnoseArithmeticOnNullPointer(Sema &S, SourceLocation Loc, << S.getLangOpts().CPlusPlus << Pointer->getSourceRange(); } +/// Diagnose invalid subraction on a null pointer. +/// +static void diagnoseSubtractionOnNullPointer(Sema &S, SourceLocation Loc, + Expr *Pointer, bool BothNull) { + // Null - null is valid in C++ [expr.add]p7 + if (BothNull && S.getLangOpts().CPlusPlus) +return; + + // Is this s a macro from a system header? + if (S.Diags.getSuppressSystemWarnings() && S.SourceMgr.isInSystemMacro(Loc)) +return; + + S.Diag(Loc, diag::warn_pointer_sub_null_ptr) + << S.getLang
[clang] c3c1826 - Set TargetCPUName for AIX to default to pwr7.
Author: Jamie Schmeiser Date: 2021-07-29T09:59:24-04:00 New Revision: c3c1826c310c42244c7cad8d0c6af3a368fcd064 URL: https://github.com/llvm/llvm-project/commit/c3c1826c310c42244c7cad8d0c6af3a368fcd064 DIFF: https://github.com/llvm/llvm-project/commit/c3c1826c310c42244c7cad8d0c6af3a368fcd064.diff LOG: Set TargetCPUName for AIX to default to pwr7. Summary: Set the TargetCPUName for AIX to default to pwr7, removing the setting of it based on the major/minor of the OS version, which previously set it to pwr4 for AIX 7.1 and earlier. The old code would also set it to pwr4 when the OS version was not specified and with the change, it will default it to pwr7 in all cases. Author: Jamie Schmeiser Reviewed By:hubert.reinterpretcast (Hubert Tong) Differential Revision: https://reviews.llvm.org/D107063 Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/aix-mcpu-default.c Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 83cab3ac00cb6..d9a6599a24160 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -403,14 +403,9 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T, if (!TargetCPUName.empty()) return TargetCPUName; -if (T.isOSAIX()) { - unsigned major, minor, unused_micro; - T.getOSVersion(major, minor, unused_micro); - // The minimal arch level moved from pwr4 for AIX7.1 to - // pwr7 for AIX7.2. - TargetCPUName = - (major < 7 || (major == 7 && minor < 2)) ? "pwr4" : "pwr7"; -} else if (T.getArch() == llvm::Triple::ppc64le) +if (T.isOSAIX()) + TargetCPUName = "pwr7"; +else if (T.getArch() == llvm::Triple::ppc64le) TargetCPUName = "ppc64le"; else if (T.getArch() == llvm::Triple::ppc64) TargetCPUName = "ppc64"; diff --git a/clang/test/Driver/aix-mcpu-default.c b/clang/test/Driver/aix-mcpu-default.c index 7b55839a80661..3bb3c7f95e1e9 100644 --- a/clang/test/Driver/aix-mcpu-default.c +++ b/clang/test/Driver/aix-mcpu-default.c @@ -2,17 +2,35 @@ // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ // RUN:-target powerpc-ibm-aix7.2 \ // RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s -// CHECK-MCPU-DEFAULT-AIX72-NOT: warning: -// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1" -// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7" -// Check that the target cpu defaults to power4 on AIX7.1 and below. +// Check that the target cpu defaults to power7 on AIX7.2 and up. +// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ +// RUN:-target powerpc64-ibm-aix7.2 \ +// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s + +// Check that the target cpu defaults to power7 on AIX7.1 and below. // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ // RUN:-target powerpc-ibm-aix7.1 \ -// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX71 %s -// CHECK-MCPU-DEFAULT-AIX71-NOT: warning: -// CHECK-MCPU-DEFAULT-AIX71: {{.*}}clang{{.*}}" "-cc1" -// CHECK-MCPU-DEFAULT-AIX71: "-target-cpu" "pwr4" +// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s + +// Check that the target cpu defaults to power7 on AIX7.1 and below. +// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ +// RUN:-target powerpc64-ibm-aix7.1 \ +// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s + +// Check that the target cpu defaults to power7 when level not specified. +// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ +// RUN:-target powerpc-ibm-aix \ +// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s + +// Check that the target cpu defaults to power7 when level not specified. +// RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ +// RUN:-target powerpc64-ibm-aix \ +// RUN: | FileCheck --check-prefix=CHECK-MCPU-DEFAULT-AIX72 %s + +// CHECK-MCPU-DEFAULT-AIX72-NOT: warning: +// CHECK-MCPU-DEFAULT-AIX72: {{.*}}clang{{.*}}" "-cc1" +// CHECK-MCPU-DEFAULT-AIX72: "-target-cpu" "pwr7" // Check that the user is able to overwrite the default with '-mcpu'. // RUN: %clang -no-canonical-prefixes %s -### -c 2>&1 \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 136ced4 - When vector is found as a type or non-type id, check if it is really the altivec vector token.
Author: Jamie Schmeiser Date: 2021-05-20T12:39:04-04:00 New Revision: 136ced498ba84f6b6126051626e319f18ba740f5 URL: https://github.com/llvm/llvm-project/commit/136ced498ba84f6b6126051626e319f18ba740f5 DIFF: https://github.com/llvm/llvm-project/commit/136ced498ba84f6b6126051626e319f18ba740f5.diff LOG: When vector is found as a type or non-type id, check if it is really the altivec vector token. Summary: Call TryAltiVecVectorToken when an identifier is seen in the parser before annotating the token. This checks the next token where necessary to ensure that vector is properly handled as the altivec token. Author: Jamie Schmeiser Reviewed By: ZarkoCA (Zarko Todorovski) Differential Revision: https://reviews.llvm.org/D100991 Added: clang/test/Parser/altivec-non-type-vector.c clang/test/Parser/altivec-template-vector.cpp clang/test/Parser/altivec-typedef-vector.c Modified: clang/lib/Parse/Parser.cpp Removed: diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 389180ea01f7..cbcbca127c9d 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1695,6 +1695,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC) { break; case Sema::NC_Type: { +if (TryAltiVecVectorToken()) + // vector has been found as a type id when altivec is enabled but + // this is followed by a declaration specifier so this is really the + // altivec vector token. Leave it unannotated. + break; SourceLocation BeginLoc = NameLoc; if (SS.isNotEmpty()) BeginLoc = SS.getBeginLoc(); @@ -1736,6 +1741,11 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC) { return ANK_Success; case Sema::NC_NonType: +if (TryAltiVecVectorToken()) + // vector has been found as a non-type id when altivec is enabled but + // this is followed by a declaration specifier so this is really the + // altivec vector token. Leave it unannotated. + break; Tok.setKind(tok::annot_non_type); setNonTypeAnnotation(Tok, Classification.getNonTypeDecl()); Tok.setLocation(NameLoc); diff --git a/clang/test/Parser/altivec-non-type-vector.c b/clang/test/Parser/altivec-non-type-vector.c new file mode 100644 index ..d0868a60d0c3 --- /dev/null +++ b/clang/test/Parser/altivec-non-type-vector.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu + +int vector(); + +void test() { + vector unsigned int v = {0}; +} diff --git a/clang/test/Parser/altivec-template-vector.cpp b/clang/test/Parser/altivec-template-vector.cpp new file mode 100644 index ..f0c1d86563fe --- /dev/null +++ b/clang/test/Parser/altivec-template-vector.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu + +template class vector { +public: + vector(int) {} +}; + +void f() { + vector int v = {0}; + vector vi = {0}; +} diff --git a/clang/test/Parser/altivec-typedef-vector.c b/clang/test/Parser/altivec-typedef-vector.c new file mode 100644 index ..5e00824b4de7 --- /dev/null +++ b/clang/test/Parser/altivec-typedef-vector.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64le-ibm-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc64-linux-gnu +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-ibm-aix-xcoff +// RUN: %clang_cc1 -target-feature +altivec -fsyntax-only %s -triple powerpc-linux-gnu + +typedef int vector; + +void test() { + vector unsigned int v = {0}; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] efbf013 - Only issue warning for subtraction involving null pointers on live code paths
Author: Jamie Schmeiser Date: 2022-06-03T10:10:37-04:00 New Revision: efbf0136b4108692ddd1a852b3f5b232c10d2097 URL: https://github.com/llvm/llvm-project/commit/efbf0136b4108692ddd1a852b3f5b232c10d2097 DIFF: https://github.com/llvm/llvm-project/commit/efbf0136b4108692ddd1a852b3f5b232c10d2097.diff LOG: Only issue warning for subtraction involving null pointers on live code paths Summary: Change the warning produced for subtraction from (or with) a null pointer to only be produced when the code path is live. https://github.com/llvm/llvm-project/issues/54570 Author: Jamie Schmeiser Reviewed By: anarazel (Andres Freund) Differential Revision: https://reviews.llvm.org/D126816 Added: Modified: clang/lib/Sema/SemaExpr.cpp clang/test/Sema/pointer-subtraction.c clang/test/Sema/pointer-subtraction.cpp Removed: diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3e8bd63e89ae9..6627aaf3e6d88 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10845,8 +10845,10 @@ static void diagnoseSubtractionOnNullPointer(Sema &S, SourceLocation Loc, if (S.Diags.getSuppressSystemWarnings() && S.SourceMgr.isInSystemMacro(Loc)) return; - S.Diag(Loc, diag::warn_pointer_sub_null_ptr) - << S.getLangOpts().CPlusPlus << Pointer->getSourceRange(); + S.DiagRuntimeBehavior(Loc, Pointer, +S.PDiag(diag::warn_pointer_sub_null_ptr) +<< S.getLangOpts().CPlusPlus +<< Pointer->getSourceRange()); } /// Diagnose invalid arithmetic on two function pointers. diff --git a/clang/test/Sema/pointer-subtraction.c b/clang/test/Sema/pointer-subtraction.c index c3dbbd47459fa..79d18a0f0a306 100644 --- a/clang/test/Sema/pointer-subtraction.c +++ b/clang/test/Sema/pointer-subtraction.c @@ -11,6 +11,16 @@ void a(void) { f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} f = (char *)((char *)0 - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} + if (1) +f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} + else +f = (char *)((char *)0 - f); + + if (0) +f = (char *)((char *)0 - f); + else +f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} + #ifndef SYSTEM_WARNINGS SYSTEM_MACRO(f); #else diff --git a/clang/test/Sema/pointer-subtraction.cpp b/clang/test/Sema/pointer-subtraction.cpp index efbb3255e5d31..28063a1fea6ef 100644 --- a/clang/test/Sema/pointer-subtraction.cpp +++ b/clang/test/Sema/pointer-subtraction.cpp @@ -11,6 +11,16 @@ void a() { f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}} f = (char *)((char *)0 - (char *)0); // valid in C++ + if (1) +f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}} + else +f = (char *)((char *)0 - f); + + if (0) +f = (char *)((char *)0 - f); + else +f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}} + #ifndef SYSTEM_WARNINGS SYSTEM_MACRO(f); #else ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
@@ -1495,7 +1496,7 @@ void TimeProfilingPassesHandler::registerCallbacks( } void TimeProfilingPassesHandler::runBeforePass(StringRef PassID, Any IR) { - timeTraceProfilerBegin(PassID, getIRName(IR)); + timeTraceProfilerBegin(PassID, demangle(getIRName(IR))); jamieschmeiser wrote: getIRName is a locally defined function (see above in this file). In most of the cases, it is desirable to have the mangled name because that can be used for filtering. In this case, I don't think that there is filtering available, so demangling the name seems reasonable. However, as you noted, there are many situations where demangling is not appropriate. I would suggest that you add a parameter to the getIRName function (defaulting to false) to allow demangling of appropriate names and do the demangling there. https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
https://github.com/jamieschmeiser requested changes to this pull request. See comments in response https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
https://github.com/jamieschmeiser edited https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
https://github.com/jamieschmeiser approved this pull request. LGTM, thanks https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
jamieschmeiser wrote: Yes, the way to proceed is to rebase and resolve the conflicts. As far as the formatting changes, I think you should go with what the formatter wants. Everyone has different opinions about things like spacing, line length, etc and will never agree. The formatter keeps things consistent, which I think everyone will agree is good. https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
jamieschmeiser wrote: @Trass3r, sorry, I didn't realize that you were waiting on me... I had already approved this so you can go ahead and merge it. I was just pointing you at possibly related work that might interest you. Even if you decide to expand this work, I would suggest delivering this as is and doing that as a separate piece. https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
jamieschmeiser wrote: To directly answer your question: No, deliver this. If you find loop entries in the future, then consider expanding it. Also, the link to that here may help others should then decide to expand this work. https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
https://github.com/jamieschmeiser closed https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
jamieschmeiser wrote: Thanks, I looked over things and they still look good. https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
jamieschmeiser wrote: You may want to look at https://github.com/llvm/llvm-project/pull/90756 https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] demangle function names in trace files (PR #87626)
jamieschmeiser wrote: @rnk It is just a convenience to make things easier to read and should be removed if it is causing compile time issues. I just happened to see this comment now but will be unavailable for about 2 weeks. I will take care of it when I return (I'm not ignoring this...) If you wish to pull it in the mean-time, please go ahead. Sorry for any inconvenience. https://github.com/llvm/llvm-project/pull/87626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dfc1e31 - Produce warning for performing pointer arithmetic on a null pointer.
Author: Jamie Schmeiser Date: 2021-05-11T11:29:50-04:00 New Revision: dfc1e31d49fe1380c9bab43373995df5fed15e6d URL: https://github.com/llvm/llvm-project/commit/dfc1e31d49fe1380c9bab43373995df5fed15e6d DIFF: https://github.com/llvm/llvm-project/commit/dfc1e31d49fe1380c9bab43373995df5fed15e6d.diff LOG: Produce warning for performing pointer arithmetic on a null pointer. Summary: Test and produce warning for subtracting a pointer from null or subtracting null from a pointer. Reuse existing warning that this is undefined behaviour. Also add unit test for both warnings. Reformat to satisfy clang-format. Respond to review comments: add additional test. Respond to review comments: Do not issue warning for nullptr - nullptr in C++. Fix indenting to satisfy clang-format. Respond to review comments: Add C++ tests. Author: Jamie Schmeiser Reviewed By: efriedma (Eli Friedman), nickdesaulniers (Nick Desaulniers) Differential Revision: https://reviews.llvm.org/D98798 Added: clang/test/Sema/pointer-addition.cpp Modified: clang/lib/Sema/SemaExpr.cpp clang/test/Sema/pointer-addition.c Removed: diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 73d7675eb189f..1390c17de9ece 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10779,7 +10779,17 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS, LHS.get(), RHS.get())) return QualType(); - // FIXME: Add warnings for nullptr - ptr. + bool LHSIsNullPtr = LHS.get()->IgnoreParenCasts()->isNullPointerConstant( + Context, Expr::NPC_ValueDependentIsNotNull); + bool RHSIsNullPtr = RHS.get()->IgnoreParenCasts()->isNullPointerConstant( + Context, Expr::NPC_ValueDependentIsNotNull); + + // Subtracting nullptr or from nullptr should produce + // a warning expect nullptr - nullptr is valid in C++ [expr.add]p7 + if (LHSIsNullPtr && (!getLangOpts().CPlusPlus || !RHSIsNullPtr)) +diagnoseArithmeticOnNullPointer(*this, Loc, LHS.get(), false); + if (RHSIsNullPtr && (!getLangOpts().CPlusPlus || !LHSIsNullPtr)) +diagnoseArithmeticOnNullPointer(*this, Loc, RHS.get(), false); // The pointee type may have zero size. As an extension, a structure or // union may have zero size or an array may have zero length. In this diff --git a/clang/test/Sema/pointer-addition.c b/clang/test/Sema/pointer-addition.c index 562f05340f7cb..ab641bd132363 100644 --- a/clang/test/Sema/pointer-addition.c +++ b/clang/test/Sema/pointer-addition.c @@ -29,4 +29,7 @@ void a(S* b, void* c) { // Cases that don't match the GNU inttoptr idiom get a diff erent warning. f = (char*)0 - i; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} int *g = (int*)0 + i; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)((char*)0 - f); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)(f - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)((char*)0 - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} } diff --git a/clang/test/Sema/pointer-addition.cpp b/clang/test/Sema/pointer-addition.cpp new file mode 100644 index 0..5e09034ed9651 --- /dev/null +++ b/clang/test/Sema/pointer-addition.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wextra -std=c++11 + +void a() { + char *f = (char*)0; + f = (char*)((char*)0 - f); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)(f - (char*)0); // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}} + f = (char*)((char*)0 - (char*)0); // valid in C++ +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits