Oil and gas giants Royal Dutch Shell (LSE: RDSB) and BP (LSE: BP) have been among the top performers in the FTSE 100 so far this year. Shell stock is worth 31% more than at the start of January, while BP is up 23%.

But these gains don’t seem to reflect the weak state of the oil market or both companies’ rapidly-growing debt piles. Are investors turning a blind eye to the risk of a dividend cut in pursuit of the 7% yields available on both stocks?

Cash flow problems at Shell?

Shell’s interim results showed that the firm’s net debt has rocketed from $25.9bn one year ago to $75.1bn today. Much of this is due to the BG acquisition. I expect Shell to be able to refinance a lot of BG’s debt at much lower interest rates than those paid by BG.

But the reality remains challenging. Shell has $10.8bn of debt due for repayment or refinancing during the next 12 months. Excluding the BG acquisition, Shell reported a net cash outflow from operations and capital expenditure of almost $8bn during the first half.

The group then paid out a further $1.26bn in interest payments and $4.7bn in dividends. By my reckoning that’s a shortfall of almost $14bn. The company was only able to square things by borrowing an additional $9.5bn during the period, and reducing its cash balance.

I expect some improvement during the second half of the year. But it’s clear that Shell’s dividend is being funded from debt and cash reserves. Shell is betting that the price of oil will recover to $50-$60 per barrel before its debt levels become problematic.

Oil could remain below $50 into 2017, but will eventually recover. The longer it stays low, the more violently the price is likely to spike upwards when demand does start to exceed supply.

A dividend cut might have been prudent for Shell and could still be necessary. However, I suspect the group’s size and ultra-low borrowing costs will mean that chief executive Ben van Beurden gets away with this crowd-pleasing gamble.

Are things better at BP?

At first glance, the situation appears to be slightly better at BP. The group reported net cash from operating activities of $5.7bn during the first half of the year, nearly twice the $2.9bn reported by Shell.

BP’s outgoings appear to be more modest too. Net cash outflow after operations and capital expenditure was only $1.6bn during the first half. BP’s borrowings rose by less than $1bn, compared to $9.5bn at Shell.

Although BP’s dividend is also being funded by borrowings and the group’s cash balance, it does look more nearly affordable to me than that of Shell.

Buy BP, sell Shell?

While I have concerns about Shell’s rocketing levels of debt, I do think the picture is being distorted by the acquisition of BG. Cash generation should improve rapidly when oil does start to recover.

I own shares in both firms and have no intention of selling either stock. I’m happy to accept the risk of a dividend cut in the expectation of further gains over the next couple of years.

Don't ignore these big cap buys

I rate Shell and BP as dividend buys, but the Motley Fool's top analysts aren't so sure. They didn't include oil stocks in their exclusive new wealth report, 5 Shares To Retire On.

The companies selected for the report all boast strong dividend growth records and robust profits.

If you're already invested in BP or Shell, you may want to consider adding some of these stocks to your portfolio as well.

This 'must-read' report is free and carries no obligation. To download your copy, just click here now.

Roland Head owns shares of BP and Royal Dutch Shell. The Motley Fool UK has recommended BP and Royal Dutch Shell B. We Fools don't all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors.