Skip to content

[clang][NFC] remove unneeded nullptr checks after dereference #100489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

mikerice1969
Copy link
Contributor

Fix static verifer concerns of null pointer checks after dereferencing
the pointer. Update the assert to make it super clear it is not null and
remove the checks.

Fix static verifer concerns of null pointer checks after dereferencing
the pointer. Update the assert to make it super clear it is not null and
remove the checks.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

@llvm/pr-subscribers-clang

Author: Mike Rice (mikerice1969)

Changes

Fix static verifer concerns of null pointer checks after dereferencing
the pointer. Update the assert to make it super clear it is not null and
remove the checks.


Full diff: https://github.com/llvm/llvm-project/pull/100489.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-4)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 04b8d88cae217..1cca8ac9b9343 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12248,16 +12248,15 @@ Decl *Sema::ActOnUsingEnumDeclaration(Scope *S, AccessSpecifier AS,
                                       SourceLocation EnumLoc, SourceRange TyLoc,
                                       const IdentifierInfo &II, ParsedType Ty,
                                       CXXScopeSpec *SS) {
-  assert(!SS->isInvalid() && "ScopeSpec is invalid");
+  assert(SS && !SS->isInvalid() && "ScopeSpec is invalid");
   TypeSourceInfo *TSI = nullptr;
   SourceLocation IdentLoc = TyLoc.getBegin();
   QualType EnumTy = GetTypeFromParser(Ty, &TSI);
   if (EnumTy.isNull()) {
-    Diag(IdentLoc, SS && isDependentScopeSpecifier(*SS)
+    Diag(IdentLoc, isDependentScopeSpecifier(*SS)
                        ? diag::err_using_enum_is_dependent
                        : diag::err_unknown_typename)
-        << II.getName()
-        << SourceRange(SS ? SS->getBeginLoc() : IdentLoc, TyLoc.getEnd());
+        << II.getName() << SourceRange(SS->getBeginLoc(), TyLoc.getEnd());
     return nullptr;
   }
 

@mikerice1969 mikerice1969 merged commit 51d4980 into llvm:main Jul 25, 2024
10 checks passed
@mikerice1969 mikerice1969 deleted the fix-unneeded-nullptr-check branch July 25, 2024 15:03
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 25, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-5 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/2641

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang Tools :: clang-doc/basic-project.test' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
Emiting docs in html format.
Mapping decls...
Collecting infos...
Reducing 5 infos...
Generating docs...
Generating assets for docs...

--
Command Output (stderr):
--
RUN: at line 1: rm -rf /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp && mkdir -p /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build
+ rm -rf /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp
+ mkdir -p /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build
RUN: at line 2: sed 's|$test_dir|/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc|g' /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/Inputs/basic-project/database_template.json > /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build/compile_commands.json
+ sed 's|$test_dir|/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc|g' /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/Inputs/basic-project/database_template.json
RUN: at line 3: clang-doc --format=html --output=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs --executor=all-TUs /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build/compile_commands.json
+ clang-doc --format=html --output=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs --executor=all-TUs /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build/compile_commands.json
[1/3] Processing file /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Rectangle.cpp
[2/3] Processing file /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp
[3/3] Processing file /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
RUN: at line 4: FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/basic-project.test -input-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs/index_json.js -check-prefix=JSON-INDEX
+ FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/basic-project.test -input-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs/index_json.js -check-prefix=JSON-INDEX
RUN: at line 5: FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/basic-project.test -input-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs/GlobalNamespace/Shape.html -check-prefix=HTML-SHAPE
+ FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/basic-project.test -input-file=/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs/GlobalNamespace/Shape.html -check-prefix=HTML-SHAPE
�[1m/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/basic-project.test:64:16: �[0m�[0;1;31merror: �[0m�[1mHTML-SHAPE: expected string not found in input
�[0m// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
�[0;1;32m               ^
�[0m�[1m/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs/GlobalNamespace/Shape.html:32:53: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0m <p>Defined at line 13 of file ./include/Shape.h</p>
�[0;1;32m                                                    ^
�[0m�[1m/Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs/GlobalNamespace/Shape.html:47:41: �[0m�[0;1;30mnote: �[0m�[1mpossible intended match here
�[0m <a href="#12896F9255F880ECD4A6482CCFA58B238FA2CC49">area</a>
�[0;1;32m                                        ^
�[0m
Input file: /Users/buildbot/buildbot-root/aarch64-darwin/build/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs/GlobalNamespace/Shape.html
Check file: /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang-tools-extra/test/clang-doc/basic-project.test

-dump-input=help explains the following input dump.

Input was:
<<<<<<
�[1m�[0m�[0;1;30m            1: �[0m�[1m�[0;1;46m<!DOCTYPE html> �[0m
�[0;1;30m            2: �[0m�[1m�[0;1;46m<meta charset="utf-8"/> �[0m
�[0;1;30m            3: �[0m�[1m�[0;1;46m<title>class Shape</title> �[0m
�[0;1;30m            4: �[0m�[1m�[0;1;46m<link rel="stylesheet" href="../clang-doc-default-stylesheet.css"/> �[0m
...

yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
Fix static verifer concerns of null pointer checks after dereferencing  
the pointer. Update the assert to make it super clear it is not null and
remove the checks.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250760
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants