[clang] [clang][NFC] Remove unused embed parameter source ranges (PR #240235)

Chen Miao via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 8 18:06:02 PST 2026


https://github.com/ChenMiaoi created https://github.com/llvm/llvm-project/pull/240235

`PPDirectiveParameter` stores a source range for each embed parameter, but `getParameterRange()` has no callers.

Remove the base class and the unused range arguments from embed parameter construction.

>From 2deb1b8b4f44a6dcc77e377b34951267b1edd570 Mon Sep 17 00:00:00 2001
From: Chen Miao <chenmiao.ku at gmail.com>
Date: Mon, 9 Nov 2026 10:03:48 +0800
Subject: [PATCH] [clang][NFC] Remove unused embed parameter source ranges

`PPDirectiveParameter` stores a source range for each embed parameter,
but `getParameterRange()` has no callers.

Remove the base class and the unused range arguments from embed
parameter construction.
---
 .../include/clang/Lex/PPDirectiveParameter.h  | 33 -------------------
 clang/include/clang/Lex/PPEmbedParameters.h   | 29 ++++++++--------
 clang/lib/Lex/PPDirectives.cpp                | 15 +++------
 3 files changed, 18 insertions(+), 59 deletions(-)
 delete mode 100644 clang/include/clang/Lex/PPDirectiveParameter.h

diff --git a/clang/include/clang/Lex/PPDirectiveParameter.h b/clang/include/clang/Lex/PPDirectiveParameter.h
deleted file mode 100644
index 83f0566d739b10..00000000000000
--- a/clang/include/clang/Lex/PPDirectiveParameter.h
+++ /dev/null
@@ -1,33 +0,0 @@
-//===--- PPDirectiveParameter.h ---------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the base class for preprocessor directive parameters, such
-// as limit(1) or suffix(x) for #embed.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_LEX_PPDIRECTIVEPARAMETER_H
-#define LLVM_CLANG_LEX_PPDIRECTIVEPARAMETER_H
-
-#include "clang/Basic/SourceLocation.h"
-
-namespace clang {
-
-/// Captures basic information about a preprocessor directive parameter.
-class PPDirectiveParameter {
-  SourceRange R;
-
-public:
-  PPDirectiveParameter(SourceRange R) : R(R) {}
-
-  SourceRange getParameterRange() const { return R; }
-};
-
-} // end namespace clang
-
-#endif
diff --git a/clang/include/clang/Lex/PPEmbedParameters.h b/clang/include/clang/Lex/PPEmbedParameters.h
index 41a69664df3667..17346742fcad77 100644
--- a/clang/include/clang/Lex/PPEmbedParameters.h
+++ b/clang/include/clang/Lex/PPEmbedParameters.h
@@ -13,7 +13,6 @@
 #ifndef LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H
 #define LLVM_CLANG_LEX_PPEMBEDPARAMETERS_H
 
-#include "clang/Lex/PPDirectiveParameter.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -21,52 +20,50 @@ namespace clang {
 
 /// Preprocessor extension embed parameter "clang::offset"
 /// `clang::offset( constant-expression )`
-class PPEmbedParameterOffset : public PPDirectiveParameter {
+class PPEmbedParameterOffset {
 public:
   size_t Offset;
 
-  PPEmbedParameterOffset(size_t Offset, SourceRange R)
-      : PPDirectiveParameter(R), Offset(Offset) {}
+  explicit PPEmbedParameterOffset(size_t Offset) : Offset(Offset) {}
 };
 
 /// Preprocessor standard embed parameter "limit"
 /// `limit( constant-expression )`
-class PPEmbedParameterLimit : public PPDirectiveParameter {
+class PPEmbedParameterLimit {
 public:
   size_t Limit;
 
-  PPEmbedParameterLimit(size_t Limit, SourceRange R)
-      : PPDirectiveParameter(R), Limit(Limit) {}
+  explicit PPEmbedParameterLimit(size_t Limit) : Limit(Limit) {}
 };
 
 /// Preprocessor standard embed parameter "prefix"
 /// `prefix( balanced-token-seq )`
-class PPEmbedParameterPrefix : public PPDirectiveParameter {
+class PPEmbedParameterPrefix {
 public:
   SmallVector<Token, 2> Tokens;
 
-  PPEmbedParameterPrefix(SmallVectorImpl<Token> &&Tokens, SourceRange R)
-      : PPDirectiveParameter(R), Tokens(std::move(Tokens)) {}
+  explicit PPEmbedParameterPrefix(SmallVectorImpl<Token> &&Tokens)
+      : Tokens(std::move(Tokens)) {}
 };
 
 /// Preprocessor standard embed parameter "suffix"
 /// `suffix( balanced-token-seq )`
-class PPEmbedParameterSuffix : public PPDirectiveParameter {
+class PPEmbedParameterSuffix {
 public:
   SmallVector<Token, 2> Tokens;
 
-  PPEmbedParameterSuffix(SmallVectorImpl<Token> &&Tokens, SourceRange R)
-      : PPDirectiveParameter(R), Tokens(std::move(Tokens)) {}
+  explicit PPEmbedParameterSuffix(SmallVectorImpl<Token> &&Tokens)
+      : Tokens(std::move(Tokens)) {}
 };
 
 /// Preprocessor standard embed parameter "if_empty"
 /// `if_empty( balanced-token-seq )`
-class PPEmbedParameterIfEmpty : public PPDirectiveParameter {
+class PPEmbedParameterIfEmpty {
 public:
   SmallVector<Token, 2> Tokens;
 
-  PPEmbedParameterIfEmpty(SmallVectorImpl<Token> &&Tokens, SourceRange R)
-      : PPDirectiveParameter(R), Tokens(std::move(Tokens)) {}
+  explicit PPEmbedParameterIfEmpty(SmallVectorImpl<Token> &&Tokens)
+      : Tokens(std::move(Tokens)) {}
 };
 
 struct LexEmbedParametersResult {
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 5ff165e3ddf81f..d122ca059ea5f6 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -3979,8 +3979,7 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
       std::optional<size_t> Limit = LexParenthesizedIntegerExpr();
       if (!Limit)
         return std::nullopt;
-      Result.MaybeLimitParam =
-          PPEmbedParameterLimit{*Limit, {ParamStartLoc, CurTok.getLocation()}};
+      Result.MaybeLimitParam = PPEmbedParameterLimit{*Limit};
     } else if (Parameter == "clang::offset") {
       if (Result.MaybeOffsetParam)
         Diag(CurTok, diag::err_pp_embed_dup_params) << Parameter;
@@ -3988,8 +3987,7 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
       std::optional<size_t> Offset = LexParenthesizedIntegerExpr();
       if (!Offset)
         return std::nullopt;
-      Result.MaybeOffsetParam = PPEmbedParameterOffset{
-          *Offset, {ParamStartLoc, CurTok.getLocation()}};
+      Result.MaybeOffsetParam = PPEmbedParameterOffset{*Offset};
     } else if (Parameter == "prefix") {
       if (Result.MaybePrefixParam)
         Diag(CurTok, diag::err_pp_embed_dup_params) << Parameter;
@@ -3997,8 +3995,7 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
       SmallVector<Token, 4> Soup;
       if (!LexParenthesizedBalancedTokenSoup(Soup))
         return std::nullopt;
-      Result.MaybePrefixParam = PPEmbedParameterPrefix{
-          std::move(Soup), {ParamStartLoc, CurTok.getLocation()}};
+      Result.MaybePrefixParam = PPEmbedParameterPrefix{std::move(Soup)};
     } else if (Parameter == "suffix") {
       if (Result.MaybeSuffixParam)
         Diag(CurTok, diag::err_pp_embed_dup_params) << Parameter;
@@ -4006,8 +4003,7 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
       SmallVector<Token, 4> Soup;
       if (!LexParenthesizedBalancedTokenSoup(Soup))
         return std::nullopt;
-      Result.MaybeSuffixParam = PPEmbedParameterSuffix{
-          std::move(Soup), {ParamStartLoc, CurTok.getLocation()}};
+      Result.MaybeSuffixParam = PPEmbedParameterSuffix{std::move(Soup)};
     } else if (Parameter == "if_empty") {
       if (Result.MaybeIfEmptyParam)
         Diag(CurTok, diag::err_pp_embed_dup_params) << Parameter;
@@ -4015,8 +4011,7 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
       SmallVector<Token, 4> Soup;
       if (!LexParenthesizedBalancedTokenSoup(Soup))
         return std::nullopt;
-      Result.MaybeIfEmptyParam = PPEmbedParameterIfEmpty{
-          std::move(Soup), {ParamStartLoc, CurTok.getLocation()}};
+      Result.MaybeIfEmptyParam = PPEmbedParameterIfEmpty{std::move(Soup)};
     } else {
       ++Result.UnrecognizedParams;
 



More information about the cfe-commits mailing list